HDU4510 模拟

腾讯马拉松

水~~

注意是12小时一周期!!!!!!!!!!!!!!!!!!!!!!!

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 struct node{
 4     int h,m,s,all;
 5 };
 6 node now,pre,tmp;
 7 int main(){
 8     int n;
 9     scanf("%d",&n);
10     while( n-- ){
11         scanf("%d:%d:%d",&now.h,&now.m,&now.s);
12         now.all = now.h*3600+now.m*60+now.s;
13         scanf("%d:%d:%d",&tmp.h,&tmp.m,&tmp.s);
14         while( tmp.h>=12 ){
15             tmp.h -= 12;
16         }
17         tmp.all = tmp.h*3600+tmp.m*60+tmp.s;
18         int tot;
19         tot = now.all - tmp.all;
20         if( tot >=0 ){ 
21             pre.h = tot/3600,tot = tot - pre.h*3600;
22             pre.m = tot/60, tot = tot - pre.m*60;
23             pre.s = tot;
24             printf("%02d:%02d:%02d\n",pre.h,pre.m,pre.s);
25         }
26         else{
27             tot=-tot;
28             pre.h = tot/3600,tot = tot - pre.h*3600;
29             pre.m = tot/60, tot = tot - pre.m*60;
30             pre.s = tot;
31             now.h=12,now.m=0,now.s=0;
32             if( now.s<pre.s ){
33                 now.m = 59;
34                 now.h = 11;
35                 now.s = 60-pre.s;
36             }
37             else {}
38             if( now.m<pre.m ){
39                 now.m += 60;
40                 now.m -= pre.m;
41                 now.h --;
42             }
43             else{
44                 now.m-=pre.m;
45             }
46             now.h-=pre.h;
47 
48             printf("%02d:%02d:%02d\n",now.h,now.m,now.s);
49         }
50     }
51     return 0;
52 }

 

posted @ 2013-03-22 22:41  xxx0624  阅读(237)  评论(0编辑  收藏  举报