题目链接
https://www.patest.cn/contests/pat-a-practise/1006
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:40Sample Output:
SC3021234 CS301133
思路分析
结构体+自己的想法比较繁琐,把时分秒转换为对应的 数字 时*10000+分*100+秒 然后比较 过于麻烦
代码
#include<iostream>
#include<cstring>
using namespace std;
struct Person
{ char number[20];//数组开小了 测试点5
char Sign_in_time[10];
char Sign_out_time[10];
int in_time;
int out_time;
}person[10];
int main()
{
//freopen("in.txt" , "r" , stdin) ;
int T;
cin>>T;
int i = 0;
if(T <=0 ) cout<<0;
while(T)
{
int hour,minute,sec;
cin>>person[i].number;
cin>>person[i].Sign_in_time;
hour = (person[i].Sign_in_time[0]-'0')*10+(person[i].Sign_in_time[1]-'0');
minute = (person[i].Sign_in_time[3]-'0')*10+(person[i].Sign_in_time[4]-'0');
sec = (person[i].Sign_in_time[6]-'0')*10+(person[i].Sign_in_time[7]-'0');
person[i].in_time = hour*10000+minute*100+sec;
//cout<<person[i].in_time<<endl;
cin>>person[i].Sign_out_time;
hour = (person[i].Sign_out_time[0]-'0')*10+(person[i].Sign_out_time[1]-'0');
minute = (person[i].Sign_out_time[3]-'0')*10+(person[i].Sign_out_time[4]-'0');
sec = (person[i].Sign_out_time[6]-'0')*10+(person[i].Sign_out_time[7]-'0');
person[i].out_time = hour*10000+minute*100+sec;
//cout<<person[i].out_time<<endl;
if(person[i].in_time > person[i].out_time)
person[i].out_time+=1000000;
T--;
i++;
}
int min = 0;
int max = 0;
for(int j = 1;j < i;j++)
{
if(person[j].in_time < person[min].in_time)
min = j;
if(person[j].out_time > person[max].out_time)
max = j;
}
cout<<person[min].number<<" "<<person[max].number<<endl;
return 0;
}