当前位置: 代码迷 >> 综合 >> 2567. 【NOIP2011模拟9.17】电话时间 (Standard IO)
  详细解决方案

2567. 【NOIP2011模拟9.17】电话时间 (Standard IO)

热度:80   发布时间:2023-10-09 12:12:02.0

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个整数或者时间,对于每个询问输出对应的答案。

Sample Input

4

0 01:02:03 04:05:06

0 23:59:59 00:00:00

1 00:00:03 3

1 23:59:58 4

Sample Output

10983

1

00:00:06

00:00:02

对于20%的数据,T ≤ 10;
对于40%的数据,T ≤ 100;
对于100%的数据,T ≤ 100000。

题解

模拟,一小时3600秒......我都不想多说了,但注意细节,我有血淋淋的教训。

代码

varn:longint;
procedure init;
vari,j,h1,m1,s1,h2,m2,s2,l:longint;s:string;
beginreadln(n);for i:=1 to n dobeginreadln(s);if s[1]='0' thenbeginh1:=(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 elsebeginh1:=(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]<>' ' dodec(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;begininit;
end.
  相关解决方案