1006 Sign In and Sign Out (25)

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

大意大意:给出每个人的进出时间,找出第一个进入和最后一个离开的
思路:用map<int, string>来保存数据, key表示进出时间,把时间化作秒作为关键词, value记录人的名字;因为在map中插入数据的时候,会按照key排序,所以用map保存数据后,map中第一个保存的就是最先进入的, 最后一个保存的就是最后离开的;
用scanf()能很方便的得到进出的时间

 1 #include<iostream>
 2 #include<map>
 3 #include<string>
 4 using namespace std;
 5 int main(){
 6   int n, i;
 7   cin>>n;
 8   map<int, string> mmap;
 9   for(i=0; i<n; i++){
10     int hr1, min1, sec1, hr2, min2, sec2;
11     string name;
12     cin>>name;
13     scanf("%d:%d:%d %d:%d:%d", &hr1, &min1, &sec1, &hr2, &min2, &sec2);
14     mmap[hr1*3600+min1*60+sec1]=name;
15     mmap[hr2*3600+min2*60+sec2]=name;
16   }
17   auto it=mmap.end();
18   cout<<mmap.begin()->second<<" "<<(--it)->second<<endl;
19   return 0;
20 }







猜你喜欢

转载自www.cnblogs.com/mr-stn/p/9152667.html