[PAT] A1006 Sign In and Sign Out(简单模拟)

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

Analysis

最早到机房的人开门,最晚离开的人锁门。输出最早开门和锁门的人的 Id。

Code(version 1.0 -struct…too complex)

用结构体处理,分别保存了每个人的sign insign out 时间,进行两次排序分别得到最早的id和最晚的id。(写的真的好麻烦…)

#include<bits/stdc++.h>
using namespace std;

struct person
{
	string id;
	int ih,im,is;
	int oh,om,os;
}p[50];

bool cmp1(person x,person y)
{
	if(x.ih!=y.ih)
		return x.ih<y.ih;
	else if(x.im!=y.im)
		return x.im<y.im;
	else if(x.is!=y.is)
		return x.is<y.is;
}

bool cmp2(person x,person y)
{
	if(x.oh!=y.oh)
		return x.oh>y.oh;
	else if(x.om!=y.om)
		return x.om>y.om;
	else if(x.os!=y.os)
		return x.os>y.os;
}
int main()
{
	int n;
	cin>>n;
	int h,m,s;
	string id;
	for(int i=0;i<n;i++)
	{
		cin>>id;
		scanf("%d:%d:%d",&h,&m,&s);
		p[i].id=id;
		p[i].ih=h;
		p[i].im=m;
		p[i].is=s;
		scanf("%d:%d:%d",&h,&m,&s);
		p[i].oh=h;
		p[i].om=m;
		p[i].os=s;
	}
	sort(p,p+n,cmp1);
	cout<<p[0].id<<" ";
	sort(p,p+n,cmp2);
	cout<<p[0].id<<endl;
	return 0;
}

Code(version 2.0 -simple)

将时间转换成秒,即时更新最早和最晚的人的id,时间保存在minnmaxn中。

#include<bits/stdc++.h>
using namespace std;

int main() 
{
	int n, minn = 90000, maxn = 0;
	cin>>n;
	string unlocked, locked;
	for(int i = 0; i < n; i++) 
	{
		string temp;
		cin >> temp;
		int h, m, s;
		scanf("%d:%d:%d", &h, &m, &s);
		int in = h * 3600 + m * 60 + s;
		scanf("%d:%d:%d", &h, &m, &s);
		int out = h * 3600 + m * 60 + s;
		if (in < minn) 
		{
			unlocked = temp;			
			minn = in;
		}
		if (out > maxn) 
		{
			locked = temp;
			maxn = out;
		}
	}
	cout << unlocked << " " << locked;
	return 0; 
}
已标记关键词 清除标记
相关推荐
课程简介: 历经半个多月的时间,Debug亲自撸的 “企业员工角色权限管理平台” 终于完成了。正如字面意思,本课程讲解的是一个真正意义上的、企业级的项目实战,主要介绍了企业级应用系统中后端应用权限的管理,其中主要涵盖了六大核心业务模块、十几张数据库表。 其中的核心业务模块主要包括用户模块、部门模块、岗位模块、角色模块、菜单模块和系统日志模块;与此同时,Debug还亲自撸了额外的附属模块,包括字典管理模块、商品分类模块以及考勤管理模块等等,主要是为了更好地巩固相应的技术栈以及企业应用系统业务模块的开发流程! 核心技术栈列表: 值得介绍的是,本课程在技术栈层面涵盖了前端和后端的大部分常用技术,包括Spring Boot、Spring MVC、Mybatis、Mybatis-Plus、Shiro(身份认证与资源授权跟会话等等)、Spring AOP、防止XSS攻击、防止SQL注入攻击、过滤器Filter、验证码Kaptcha、热部署插件Devtools、POI、Vue、LayUI、ElementUI、JQuery、HTML、Bootstrap、Freemarker、一键打包部署运行工具Wagon等等,如下图所示: 课程内容与收益: 总的来说,本课程是一门具有很强实践性质的“项目实战”课程,即“企业应用员工角色权限管理平台”,主要介绍了当前企业级应用系统中员工、部门、岗位、角色、权限、菜单以及其他实体模块的管理;其中,还重点讲解了如何基于Shiro的资源授权实现员工-角色-操作权限、员工-角色-数据权限的管理;在课程的最后,还介绍了如何实现一键打包上传部署运行项目等等。如下图所示为本权限管理平台的数据库设计图: 以下为项目整体的运行效果截图: 值得一提的是,在本课程中,Debug也向各位小伙伴介绍了如何在企业级应用系统业务模块的开发中,前端到后端再到数据库,最后再到服务器的上线部署运行等流程,如下图所示:
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页