jzoj 2567. 【NOIP2011模拟9.17】电话时间

发布于 2019-03-29  921 次阅读


题目描述

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

输入

输入文件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格式。

输出

输出文件phone.out包含T个整数或者时间,对于每个询问输出对应的答案

思路

。。。
小学数学题,只要在出现负数时特殊判断就可以了

var
  a:array[1..10000] of longint;
  i,j,k,h,n,m,s,s1,x,y:longint;
  st:string;
begin
  readln(n);
  for i:=1 to n do
    begin
      readln(st);
      val(st[1],x);
      delete(st,1,2);
      if x=0 then
        begin
          for j:=1 to 6 do
            begin
              val(copy(st,1,2),a[j]);
              delete(st,1,3);
              if (j=1) or (j=4)
                then if a[j]=0 then a[j]:=24;
            end;
          s:=a[1]*3600+a[2]*60+a[3];
          s1:=a[4]*3600+a[5]*60+a[6];
          if (s1-s)<0 then s1:=s1+3600*24; 
          writeln(s1-s);
        end
      else
        begin
          for j:=1 to 3 do
            begin
              val(copy(st,1,2),a[j]);
              delete(st,1,3);
              if (j=1)
                then if a[j]=0 then a[j]:=24;
            end;
          val(st,y);
          s:=a[1]*3600+a[2]*60+a[3];
          s:=s+y;
          a[4]:=s div 3600;
          a[4]:=a[4] mod 24;
          s:=s mod 3600;
          a[5]:=s div 60;
          s:=s mod 60;
          a[6]:=s;
                    if (a[4]<10) and (a[4]<>0)
              then write(0);
          if a[4]=0 then write('00:')
            else write(a[4],':');
            if (a[5]<10) and (a[5]<>0)
              then write(0);
          if a[5]=0 then write('00:')
            else write(a[5],':');
            if (a[6]<10) and (a[6]<>0)
              then write(0);
          if a[6]=0 then write('00')
            else write(a[6]);
          writeln;
          end;
    end;
end.
]]>