前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PAT 1006

PAT 1006

作者头像
week
发布2018-08-27 10:18:37
2240
发布2018-08-27 10:18:37
举报
文章被收录于专栏:用户画像

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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

Sample Output:

代码语言:javascript
复制
SC3021234 CS301133
代码语言:javascript
复制
#include <iostream>
#include <string>
using namespace std;
struct Record{
	string id_number;
	string sign_in_time;
	string sign_out_time;
};
bool bigger(string a,string b)
{
	int i;
	for(i=0;i<8;i++)
	{
		if(a[i]-b[i]>0)
		{
			return true;
		}
		else if(a[i]-b[i]<0)
		{
			return false;
		}
	}
}
int main()
{
	int n,i;
	int unlocked=0,locked=0;
	string id,inTime,outTime;
	cin>>n;
	Record* records=new Record[n];

	for(i=0;i<n;i++)
	{
		cin>>id;
		cin>>inTime;
		cin>>outTime;
		records[i].id_number=id;
		records[i].sign_in_time=inTime;
		records[i].sign_out_time=outTime; 
	}
	for(i=1;i<n;i++)
	{
		if(bigger(records[unlocked].sign_in_time,records[i].sign_in_time))
		{
			unlocked=i;
		}
		if(bigger(records[i].sign_out_time,records[locked].sign_out_time))
		{
			locked=i;
		}
	}
	cout<<records[unlocked].id_number<<" "<<records[locked].id_number<<endl;
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年02月28日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1006. Sign In and Sign Out (25)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档