JZOJ8.15(C组)电话时间

    xiaoxiao2025-09-11  526

    题目:某人总是花很多时间给父母打电话。有一次他记录了打电话的开始时间和结束时刻t1和t2,请你帮他算算此次通话一共用了多少秒。又有一次,他记录了打电话的开始时刻t1和通话的时间长度len,请你帮他计算他在什么时刻结束通话。

    已知每次通话时间小于24个小时。

    分析:

    纯模拟啦。

    附上代码:

    var   t,q:longint;   hour,min,sec:array [1..2] of longint; procedure init; var   i,h,m,se,pass:longint;   s:string; begin   readln(t);   for i:=1 to t do     begin       readln(s);       val(copy(s,1,1),q);       delete(s,1,pos(' ',s));       if q=0 then         begin           val(copy(s,1,pos(':',s)-1),hour[1]);           delete(s,1,pos(':',s));           val(copy(s,1,pos(':',s)-1),min[1]);           delete(s,1,pos(':',s));           val(copy(s,1,pos(' ',s)-1),sec[1]);           delete(s,1,pos(' ',s));           val(copy(s,1,pos(':',s)-1),hour[2]);           delete(s,1,pos(':',s));           val(copy(s,1,pos(':',s)-1),min[2]);           delete(s,1,pos(':',s));           val(s,sec[2]);           if hour[2]<hour[1] then             hour[2]:=hour[2]+24           else             if hour[2]=hour[1] then               if min[2]<min[1] then                 hour[2]:=hour[2]+24               else                 if (sec[2]<sec[1]) and (min[2]=min[1]) then                   hour[2]:=hour[2]+24;           if sec[2]<sec[1] then             begin               sec[2]:=sec[2]+60;               min[2]:=min[2]-1;             end;           if min[2]<min[1] then             begin               hour[2]:=hour[2]-1;               min[2]:=min[2]+60;             end;           h:=hour[2]-hour[1];           m:=min[2]-min[1];           se:=sec[2]-sec[1];           writeln(h*3600+m*60+se);         end;       if q=1 then         begin           val(copy(s,1,pos(':',s)-1),hour[1]);           delete(s,1,pos(':',s));           val(copy(s,1,pos(':',s)-1),min[1]);           delete(s,1,pos(':',s));           val(copy(s,1,pos(' ',s)-1),sec[1]);           delete(s,1,pos(' ',s));           val(s,pass);           sec[1]:=sec[1]+pass;           if sec[1]>=60 then             begin               min[1]:=min[1]+sec[1] div 60;               sec[1]:=sec[1] mod 60;             end;           if min[1]>=60 then             begin               hour[1]:=hour[1]+min[1] div 60;               min[1]:=min[1] mod 60;             end;           if hour[1]>=24 then             hour[1]:=hour[1]-24;           str(hour[1],s);           if length(s)=1 then             s:='0'+s;           write(s,':');           str(min[1],s);           if length(s)=1 then             s:='0'+s;           write(s,':');           str(sec[1],s);           if length(s)=1 then             s:='0'+s;           writeln(s);         end;     end; end; begin   assign(input,'phone.in');reset(input);   assign(output,'phone.out');rewrite(output);   init;   close(input);close(output); end.

    转载请注明原文地址: https://ju.6miu.com/read-1302534.html
    最新回复(0)