Posted on 2009-06-03 15:44
Hero 阅读(81)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //1226 Accepted 0 192 1755 C++
2
3 #include <iostream>
4 #include <string>
5 #include <algorithm>
6 using namespace std ;
7
8 const int size = 2000 ;
9
10 int tnum ;
11 int inn ;
12
13 int h, m, s ;
14 int t ;
15 char sign ;
16
17 int data[10] ;
18
19 void print( int hh, int mm, int ss )
20 {
21 if( hh < 10 ) printf( "0%d", hh ) ;
22 else printf( "%d", hh ) ;
23
24 printf( ":" ) ;
25
26 if( mm < 10 ) printf( "0%d", mm ) ;
27 else printf( "%d", mm ) ;
28
29 printf( ":" ) ;
30
31 if( ss < 10 ) printf( "0%d", ss ) ;
32 else printf( "%d", ss ) ;
33 }
34 int main()
35 {
36 while( cin >> tnum )
37 {
38 while( tnum -- )
39 {
40 scanf( "%d", &inn ) ;
41 while( sign=getchar() )
42 {
43 if( sign == '+' )
44 {
45 scanf( "%d%*c%d%*c%d%*c", &h, &m, &s ) ;
46 t = h*60*60 + m*60 + s ;
47 break ;
48 }
49 else if( sign == '-' )
50 {
51 scanf( "%d%*c%d%*c%d%*c", &h, &m, &s ) ;
52 t = h*60*60 + m*60 + s ;
53 t = t * (-1) ;
54 break ;
55 }
56 }
57
58 for( int i=1; i<=inn; i++ )
59 {
60 scanf( "%d%*c%d%*c%d%*c", &h, &m, &s ) ;
61 int total = h*60*60 + m*60 + s ;
62 total += t ;
63 if( total <= 0 )
64 {
65 h = m = s = 0 ;
66 }
67 else
68 {
69 h = total / (60*60) ; total = total % (60*60) ;
70 m = total / 60 ; total = total % 60 ;
71 s = total ;
72 }
73
74 print( h, m, s ) ;
75
76 while( (sign=getchar()) != ' ' ) ;
77
78 printf( " --> " ) ;
79
80 scanf( "%d%*c%d%*c%d%*c", &h, &m, &s ) ;
81
82 total = h*60*60 + m*60 + s ;
83 total += t ;
84 if( total <= 0 )
85 {
86 h = m = s = 0 ;
87 }
88 else
89 {
90 h = total / (60*60) ; total = total % (60*60) ;
91 m = total / 60 ; total = total % 60 ;
92 s = total ;
93 }
94
95 print( h, m, s ) ;
96 printf( "\n" ) ;
97 }
98
99 printf( "\n" ) ;
100 }
101 }
102
103 return 0 ;
104 }