xD
uses crt;
var
dt,t1,t2:LongInt;
function GetTime:LongInt;
var
substr,str:string;
ERR,step,spacepos,code,num:Integer;
t:longint;
begin
ERR:=0;
repeat
t:=0;
step:=1;
if ERR<>0 then writeln('Nepravilnie dannie, povtorite vvod:');
ERR:=0;
readln(str);
str:=str+' ';
repeat
spacepos:=pos(' ',str);
if (spacepos<>0) then
begin
substr:=copy(str,1,spacepos-1);
delete(str,1,spacepos);
val(substr,num,code);
if code=0 then
begin
if (step=1) then begin if (num>=0) and (num<=23) then t:=t+num*60*60 else ERR:=3; end;
if (step=2) then begin if (num>=0) and (num<=59) then t:=t+num*60 else ERR:=3;end;
if (step=3) then begin if (num>=0) and (num<=59) then t:=t+num else ERR:=3;end;
inc(step);
end
else ERR:=2;
end else ERR:=1;
until ((step=4) or (err<>0));
until err=0;
GetTime:=t;
end;
begin
writeln('pervoe vremy:');
t1:=GetTime;
writeln('vtoroe vremy:');
t2:=GetTime;
if t2>=t1 then dt:=t2-t1 else dt:=t2-t1+24*60*60;
writeln('raznica v sekundah: ');
writeln(dt);
end.
Массив по убыванию:
#include<stdio.h>
#include<conio.h>
int numb[11];
int i,a,n;
int main()
{
//clrscr();
for(i=0;i<=10;i++)
{
numb[i]=i;
printf (" %d",numb[i]);
}
n=1;
while(n)
{
n=0;
for(i=0;i<10;i++)
{
if (numb[i]<numb[i+1])
{
n=1;
a=numb[i+1];numb[i+1]=numb[i];
numb[i]=a;
}
}
}
for(i=0;i<=10;i++)
printf(" %d ",numb[i]);
getch();
return 0;
}
Сортировка массива по последней цифре:
#include <bits/stdc++.h>
using namespace std;
bool f(const int rhs, const int lhs)
{
return (rhs % 10 < lhs % 10);
}
int main() {
int n;
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n, f);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
delete [] arr;
system("pause");
return 0;
}