1006. Sign in and sign out (25)

Source: Internet
Author: User

The topics are as follows:

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
title requirements from some records to find the earliest entry and the latest departure, only for this purpose, do not need to store the data, but should be dynamic record minimum and maximum, the final output, the realization of the idea is to check each record, if found new records of sign The in time is earlier than the current stored sign in the earliest time, then the update MiniD and the earliest sign in time, for sigh out time in the same way, so that the last MiniD and Maxid is to be asked.

The details of the topic is the storage and processing of characters, first set up a char array to cache the newly entered ID, two time, note that the size of the char array should be ≥ the number of characters +1, while establishing two with the previous size of the char array stored in the first sign in the MiniD and the latest sign Out of the MAXID, in addition to establish a structure to store time after the resolution of the value of time, minutes and seconds.

Precautions:

1. When assigning the newly entered ID (set this variable to newid) to MiniD and Maxid, use the strcpy function instead of assigning the value directly with =!

2. For three strings with a space-delimited input, use scanf ("%s%s",...) to determine the delimiter with the characters between%s.

3. Using advanced compilers such as VS etc. can use functions without header files, such as strcpy in the subject, remember to add string.h, or compile errors.

The AC code is as follows:

#include <iostream> #include <string.h>using namespace std;typedef struct time_s * time;struct time_s{int  Hour  int minute; int second;}; int Chartonum (char c) {return C-' 0 ';}  void Settimewithbuffer (char s[9], time t) {t->hour = Chartonum (S[0]) * + chartonum (s[1]);  T->minute = Chartonum (s[3]) * + chartonum (s[4]); T->second = Chartonum (s[6]) * + chartonum (s[7]);}  int main () {char newid[16] = {0};  Char minid[16] = {0};  Char maxid[16] = {0};  time_s Mintime, MaxTime, NewTime;  Mintime.hour = 25;  Maxtime.hour =-1;  int N;  Char intime[9] = {0}, outtime[9] = {0};  Cin >> N;  BOOL Setkey = false;    for (int i = 0; i < N; i++) {scanf ("%s%s%s", NewID, InTime, outtime);    Settimewithbuffer (InTime, &newtime);    if (Newtime.hour < mintime.hour) {Setkey = true;      } else if (Newtime.hour = = Mintime.hour) {if (Newtime.minute < Mintime.minute) {Setkey = true; } else if (Newtime.minute = = MINTIME.MInute) {if (Newtime.second < Mintime.second) {Setkey = true;      }}} if (Setkey) {Setkey = false;      strcpy (MiniD, NewID);      Mintime.hour = Newtime.hour;      Mintime.minute = Newtime.minute;    Mintime.second = Newtime.second;    } settimewithbuffer (Outtime, &newtime);    if (Newtime.hour > Maxtime.hour) {Setkey = true;      } else if (Newtime.hour = = Maxtime.hour) {if (Newtime.minute > Maxtime.minute) {Setkey = true;         } else if (Newtime.minute = = Maxtime.minute) {if (Newtime.second > Maxtime.second) {Setkey = true;      }}} if (Setkey) {Setkey = false;      strcpy (Maxid, NewID);      Maxtime.hour = Newtime.hour;      Maxtime.minute = Newtime.minute;    Maxtime.second = Newtime.second;  }} printf ("%s%s\n", MiniD, Maxid); return 0;}


1006. Sign in and sign out (25)

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.