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
#include<cstdio> #include<cstring> using namespace std; struct pNode{ char name[20]; int hh,mm,ss; }temp,early,late; bool bigger(pNode a,pNode b){ //传进来两个时间 如果a时间大于b时间 返回true if(a.hh != b.hh) return a.hh > b.hh; if(a.mm != b.mm) return a.mm > b.mm; return a.ss > b.ss; } int main(){ int n; scanf("%d",&n); early.hh = 24,early.mm = 60,early.ss = 60; //early时间最大,找最小 late.hh = 0,late.mm = 0,late.ss = 0; for(int i = 0; i < n; i++){ scanf("%s %d:%d:%d ",&temp.name,&temp.hh,&temp.mm,&temp.ss); if(bigger(temp,early) == false) early = temp; //temp的时间要小于early,结果要false scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss); if(bigger(temp,late) == true) late = temp; //temp的时间要大于late,结果要true } printf("%s %s\n",early.name,late.name); return 0; }
20190716
#include<stdio.h> #include<string.h> #define MAX -1 #define MIN 24*60*60 const int maxn = 20; int transfer(int hh,int mm,int ss) { return hh*60*60 + mm * 60 + ss; } int main() { int n; scanf("%d",&n); char minStr[maxn],maxStr[maxn],str[maxn]; int hh,mm,ss; int min = MIN,max = MAX; int temp; for(int i = 0; i < n; i++) { scanf("%s %d:%d:%d",str,&hh,&mm,&ss); temp = transfer(hh,mm,ss); if(temp < min) { min = temp; strcpy(minStr,str); } scanf("%d:%d:%d",&hh,&mm,&ss); temp = transfer(hh,mm,ss); if(temp > max) { max = temp; strcpy(maxStr,str); } } printf("%s %s",minStr,maxStr); return 0; }
#include<cstdio> #include<algorithm> using namespace std; struct person { char id[20]; int hh,mm,ss; }temp,early,late; void init() { //将最早的时间初始化位25:00:00不行 early.hh = 24,early.hh = 60,early.ss = 60; late.hh = 0,late.mm = 0,late.ss = 0; } //a的时间大于b的时间 ==>a的时间晚于b的时间 bool bigger(person a,person b) { if(a.hh != b.hh) return a.hh > b.hh; else if(a.mm != b.mm) return a.mm > b.mm; else return a.ss > b.ss; } int main() { int n; init(); scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%s %d:%d:%d",temp.id,&temp.hh,&temp.mm,&temp.ss); //如果temp的时间比early时间大是假 ==> temp时间早于early时间 if(bigger(temp,early) == false) early = temp; scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss); //temp时间 晚于 late 的时间 if(bigger(temp,late) == true) late = temp; } printf("%s %s",early.id,late.id); return 0; }