Задачи про время. Решения.

{Текущее показание часов m ч (0 <= m <= 23), n мин (0 <= n <= 59),
k сек (0 <= k <= 59). Какое время будут показывать часы через p ч (0 <= p <= 100)
q мин (0 <= q <= 59) r сек (0 <= r <= 59)?}

Label 1,2,3,4,5,6;

var

m,n,k,p,q,r,n1,n2,n3:integer;

begin

1: Write ('Vvedi chas =');
Readln (m);
If (m<0) or (m>23) then goto 1;

2: Write ('Vvedi minuty =');
Readln (n);
If (n<0) or (n>59) then goto 2;

3: Write ('Vvedi sekundy =');
Readln (k);
If (k<0) or (k>59) then goto 3;

Writeln ('Cherez skolko?');

4: Write ('Vvedi chas =');
Readln (p);
If (p<0) or (p>100) then goto 4;

5: Write ('Vvedi minuty =');
Readln (q);
If (q<0) or (q>59) then goto 5;

6: Write ('Vvedi sekundy =');
Readln (r);
If (r<0) or (r>59) then goto 6;

n1:=k+r;
If n1>59 then begin
n2:=1;
n1:=n1-60;
end;

n2:= n2+n+q;
If n2>59 then begin
n3:=1;
n2:=n2-60;
end;

n3:= n3+m+p;
If n3>23 then begin
while n3>24 do
n3:=n3-24;
end;

Writeln ('budet ',n3, ':',n2, ':',n1);
end.

Задача 2.

Label 1,2,3,4,5,6;

var
g1,m1,d1,g2,m2,d2, i, v, t,p,rez, rezg, rezd, rezm:integer;
vis:array [1..100] of integer;

begin

1: Write('God rogdenia=');
Readln(g1);
if (g1>2014) or (g1<1900) then goto 1;

i:=1;
vis[1]:=2012;
v:=2012;

While v>=g1+4 do
begin
v:=v-4;
i:=i+1;
vis[i]:=v;
end;

p:=i;

2: Write('Mesjac rogdenia=');
Readln(m1);
if (m1>12) or (m1<1) then goto 2;

3: Write ('Den rogdenia=');
Readln (d1);

If (m1=2) and (d1=29)  then begin
For i:=1 to p do
if g1=vis[i] then  t:=1;
if t=0 then goto 3;
end;
If (m1=2) and (d1>29)  then goto 3;

case m1 of
1,3,5,7,8,10,12: if (d1>31) then goto 3;
4,6,9,11: if (d1>30) then goto 3;
end;

4: Write('God teper=');
Readln(g2);
if (g1>2014) or (g2<g1) then goto 4;

5: Write('Mesjac teper=');
Readln(m2);
if (m2>12) or (m2<1) then goto 5;

6: Write ('Den teper=');
Readln (d2);

If (m2=2) and (d2=29)  then begin
For i:=1 to p do
if g2=vis[i] then  t:=1;
if t=0 then goto 6;
end;
If (m2=2) and (d2>29)  then goto 6;

case m2 of
1,3,5,7,8,10,12: if (d2>31) then goto 6;
4,6,9,11: if (d2>30) then goto 6;
end;

If (m2>m1) then
begin
rezg:=g2-g1;
rezm:=m2-m1;
rezd:=d2-d1;
end
else
begin
rezg:=g2-g1-1;
rezm:=m2-m1;
rezd:=d2-d1;
end;

rez:= rezg*365+rezd+p+rezm*30;

Writeln('progito ', rez,' dney');

end.

Комментариев нет:

Отправить комментарий