1006. Sign In and Sign Out

1006. Sign In and Sign Out (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

Input Specification:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.

Output Specification:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

Sample Input:
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output:
SC3021234 CS301133
  1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <string>
5 #include <algorithm>
6 #include <map>
7 #include <stack>
8 #include <cmath>
9 #include <queue>
10 #include <set>
11
12
13 using namespace std;
14
15 class Time
16 {
17 public:
18 int hour;
19 int minute;
20 int second;
21
22 string toString()
23 {
24 string result;
25 result.clear();
26
27 result.push_back( '0' + hour/10 );
28 result.push_back( '0' + hour%10 );
29 result.push_back(':');
30 result.push_back( '0' + minute/10 );
31 result.push_back( '0' + minute%10 );
32 result.push_back(':');
33 result.push_back( '0' + second/10 );
34 result.push_back( '0' + second%10 );
35
36 return result;
37
38 }
39 };
40
41
42 class Record
43 {
44 public :
45
46 string id;
47
48 Time in;
49 Time out;
50
51 };
52
53 bool comp1 ( const Record &r1 , const Record &r2 )
54 {
55 if( r1.in.hour != r2.in.hour )
56 {
57 return r1.in.hour < r2.in.hour;
58 }
59 else if ( r1.in.minute != r2.in.minute )
60 {
61 return r1.in.minute < r2.in.minute;
62 }
63 else
64 {
65 return r1.in.second < r2.in.second;
66 }
67 }
68
69 bool comp2 ( const Record &r1 , const Record &r2 )
70 {
71 if( r1.out.hour != r2.out.hour )
72 {
73 return r1.out.hour > r2.out.hour;
74 }
75 else if ( r1.out.minute != r2.out.minute )
76 {
77 return r1.out.minute > r2.out.minute;
78 }
79 else
80 {
81 return r1.out.second > r2.out.second;
82 }
83 }
84
85
86 int main()
87 {
88
89
90
91 int num_case = 0;
92 vector<Record> v_record;
93
94 while( cin >> num_case )
95 {
96 v_record.clear();
97 for( int i = 0 ; i < num_case ; ++i )
98 {
99 string id;
100
101 cin >> id;
102
103 Record record;
104
105 record.id = id;
106
107 int hh = 0;
108 int mm = 0;
109 int ss = 0;
110
111 char ch;
112
113
114 while( ch = cin.get() )
115 {
116 if( ch >= '0' && ch <='9' )
117 {
118 break;
119 }
120 }
121 hh += ch - '0';
122 hh*= 10;
123
124 while( ch = cin.get() )
125 {
126 if( ch >= '0' && ch <='9' )
127 {
128 break;
129 }
130 }
131 hh += ch - '0';
132
133 while( ch = cin.get() )
134 {
135 if( ch >= '0' && ch <='9' )
136 {
137 break;
138 }
139 }
140 mm += ch - '0';
141 mm*= 10;
142
143 while( ch = cin.get() )
144 {
145 if( ch >= '0' && ch <='9' )
146 {
147 break;
148 }
149 }
150 mm += ch - '0';
151
152 while( ch = cin.get() )
153 {
154 if( ch >= '0' && ch <='9' )
155 {
156 break;
157 }
158 }
159 ss += ch - '0';
160 ss*= 10;
161
162 while( ch = cin.get() )
163 {
164 if( ch >= '0' && ch <='9' )
165 {
166 break;
167 }
168 }
169 ss += ch - '0';
170
171
172 record.in.hour = hh;
173 record.in.minute = mm;
174 record.in.second = ss;
175
176
177 hh = 0;
178 mm = 0;
179 ss = 0;
180
181 while( ch = cin.get() )
182 {
183 if( ch >= '0' && ch <='9' )
184 {
185 break;
186 }
187 }
188 hh += ch - '0';
189 hh*= 10;
190
191 while( ch = cin.get() )
192 {
193 if( ch >= '0' && ch <='9' )
194 {
195 break;
196 }
197 }
198 hh += ch - '0';
199
200 while( ch = cin.get() )
201 {
202 if( ch >= '0' && ch <='9' )
203 {
204 break;
205 }
206 }
207 mm += ch - '0';
208 mm*= 10;
209
210 while( ch = cin.get() )
211 {
212 if( ch >= '0' && ch <='9' )
213 {
214 break;
215 }
216 }
217 mm += ch - '0';
218
219 while( ch = cin.get() )
220 {
221 if( ch >= '0' && ch <='9' )
222 {
223 break;
224 }
225 }
226 ss += ch - '0';
227 ss*= 10;
228
229 while( ch = cin.get() )
230 {
231 if( ch >= '0' && ch <='9' )
232 {
233 break;
234 }
235 }
236 ss += ch - '0';
237
238
239
240 record.out.hour = hh;
241 record.out.minute = mm;
242 record.out.second = ss;
243
244 v_record.push_back(record);
245
246 }
247
248 sort( v_record.begin() , v_record.end() , comp1 );
249
250 cout << v_record[0].id << " ";
251
252 sort( v_record.begin() , v_record.end() , comp2 );
253
254 cout << v_record[0].id <<endl;
255 }
256
257
258
259
260 return 0;
261 }


posted on 2012-01-30 13:21  坑王  阅读(270)  评论(0编辑  收藏  举报

导航