Description
某人总是花很多时间给父母打电话。有一次他记录了打电话的开始时间和结束时刻t1和t2,请你帮他算算此次通话一共用了多少秒。又有一次,他记录了打电话的开始时刻t1和通话的时间长度len,请你帮他计算他在什么时刻结束通话。 已知每次通话时间小于24个小时。
Input
输入文件phone.in的第一行为一个正整数T,表示了数据组数。 接下来T行,每行第一个数为k: 如果k = 0,接下来包含两个时间t1和t2,表示了打电话的开始时间和结束时刻,用一个空格隔开,时间格式为HH:MM:SS,其中0≤HH≤23,0≤MM,SS≤59。HH、MM和SS都是两位数字,因此0:1:2是不合法的时间(应写作00:01:02)。你应该对这个询问输出通话时间长度,答案一定为区间[0,86400)之内的非负整数。 如果k=1,接下来包含一个时间t1和一个非负整数len,表示了打电话的开始时刻与通话时间长度,用一个空格隔开,时间格式同为HH:MM:SS,同样时间小于24个小时,即len<86400。你应该对这个询问输出结束通话的时刻,同为HH:MM:SS格式。
Output
输出文件phone.out包含T个整数或者时间,对于每个询问输出对应的答案。
题解 暴力吧
代码
var n:longint; procedure init; var i,j,h1,m1,s1,h2,m2,s2,l:longint; s:string; begin readln(n); for i:=1 to n do begin readln(s); if s[1]='0' then begin h1:=(ord(s[3])-48)*10+(ord(s[4])-48); m1:=(ord(s[6])-48)*10+(ord(s[7])-48); s1:=(ord(s[9])-48)*10+(ord(s[10])-48); h2:=(ord(s[12])-48)*10+(ord(s[13])-48); m2:=(ord(s[15])-48)*10+(ord(s[16])-48); s2:=(ord(s[18])-48)*10+(ord(s[19])-48); if s2<s1 then begin s2:=s2+60; m2:=m2-1; end; if m2<m1 then begin m2:=m2+60; h2:=h2-1; end; if h2<h1 then h2:=h2+24; writeln((h2*3600+m2*60+s2)-(h1*3600+m1*60+s1)); end else begin h1:=(ord(s[3])-48)*10+(ord(s[4])-48); m1:=(ord(s[6])-48)*10+(ord(s[7])-48); s1:=(ord(s[9])-48)*10+(ord(s[10])-48); j:=length(s); while s[j]<>' ' do dec(j); j:=j+1; val(copy(s,j,length(s)-j+1),l); s1:=s1+l; if s1>=60 then begin m1:=m1+s1 div 60; s1:=s1 mod 60; end; if m1>=60 then begin h1:=h1+m1 div 60; m1:=m1 mod 60; end; if h1>=24 then h1:=h1 mod 24; if h1<10 then write('0'); write(h1,':'); if m1<10 then write('0'); write(m1,':'); if s1<10 then write('0'); writeln(s1); end; end; end; begin init; end.