PAT 1006. Sign in and sign out (25)

Source: Internet
Author: User

1006. Sign in and sign out (25)

At the beginning of every day, the first person who signs in the computer, the unlock, and the last one who Signs out would lock the door. Given the records of signing in's and out ' s, you're supposed to find the ones who has unlocked and locked the door on th At day.

Input Specification:

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

Id_number Sign_in_time Sign_out_time

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

Output Specification:

For each test case, the output in one line of the ID numbers of the persons who has unlocked and locked the door on. The ID numbers must is separated by one space.

Note:it is guaranteed, the records is consistent. That was, the sign in time must was earlier than the sign off time for each person, and there was no, and persons sign in or Out at the same moment.

Sample Input:
3cs301111 15:30:28 17:00:10sc3021234 08:00:00 11:25:25cs301133 21:45:00 21:58:40
Sample Output:
SC3021234 CS301133
#include <iostream> #include <string>using namespace Std;class record{private:string id;string sign_in; String Sign_out;public:friend istream& operator>> (istream& is, record& item); friend BOOL Cmp_in ( record& LHS, record& RHS); friend bool Cmp_out (record& LHS, record& rhs); string GetId () {return ID;} String Getin () {return sign_in;} String Getout () {return sign_out;}}; istream& operator>> (istream& is, record& item) {is >> item.id >> item.sign_in >> Item . Sign_out;return is;} BOOL Cmp_in (record& LHS, record& RHS) {return lhs.sign_in > rhs.sign_in;} BOOL Cmp_out (record& LHS, record& RHS) {return lhs.sign_out > rhs.sign_out;}  int main () {Record min_in, max_out, tmp;string id_in, Id_out;int recordnum;cin >> recordnum;cin >> tmp;min_in = Max_out = TMP;ID_IN = tmp. GetId (); id_out = tmp. GetId (); while (--recordnum) {cin >> tmp;if (cmp_in (min_in, tmp)) {min_in = TMP;ID_IN = tmp. GetId ();} If (Cmp_out (TMP, max_out)) {max_out = Tmp;id_out = tmp. GetId ();}} cout << id_in << "<< id_out;}

PAT 1006. Sign in and sign out (+)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.