已知每次通话时间小于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.