【一只蒟蒻的刷题历程】【PAT (Advanced Level) Practice】 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:40

Sample Output:

SC3021234 CS301133


题目大意:

1006登录和注销(25分)

每天开始时,第一个登录计算机房的人将打开门,而最后一个退出计算机的人将锁门。根据签到和签出的记录,您应该找到当天已解锁并锁定门的人。

输入规格:

每个输入文件包含一个测试用例。每个案例包含一天的记录。大小写以一个正整数M开头,该整数是记录的总数,然后是M行,每行的格式为:

ID_number登录时间Sign_out_time
时间以HH:MM:SS格式给出,ID_number是不超过15个字符的字符串。

输出规格:

对于每个测试用例,请在一行中输出当天解锁和锁定门的人员的ID号。两个ID号必须用一个空格隔开。

注意:保证记录是一致的。也就是说,每个人的登录时间必须早于退出时间,并且没有两个人可以同时登录或退出。

样本输入:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

样本输出:

SC3021234 CS301133


代码:

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
int main() 
{
   int m;
   string opentime,closetime;  //记录开门时间,关门时间 
   string opener,closer;    //记录开门者,关门者 
   cin>>m;
   
   
   for(int i=0;i<m;i++)
   {
   	  string s1,s2,s3; 
   	  cin>>s1>>s2>>s3;
   	  if(i==0)   
   	  //把所有事情都先看作是第一个人干的,更新开关门时间,开关门的人
   	  {
   	  	 opentime=s2;
   	  	 closetime=s3;
   	  	 opener=s1;
   	  	 closer=s1;
	  }
	  else
	  {
	  	 if(opentime>s2) //更新开门时间和开门的人
	  	 {
	  	 	opentime=s2; 
	  	 	opener=s1;
		 }
		 if(closetime<s3) //更新关门时间和关门的人
		 {
		 	closetime=s3;
		 	closer=s1;
		 }
	  }
   }
   cout<<opener<<" "<<closer; //输出就行了
    return 0;
}

原创文章 32 获赞 35 访问量 1518

猜你喜欢

转载自blog.csdn.net/weixin_45260385/article/details/105893268
今日推荐