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

解题思路:

题意就是找到最早签到和最晚签离的人,首先可用一个结构体person来存储姓名和小时,分钟,秒。设置结构体型变量start,end来分别存储最早签到和最晚签离的人的信息,而temp则存储每次读入的人的信息。这里需要注意temp可以先读入签到时间,与start比较完后,再读入签离时间,与end比较。最终start就是最早签到的人的信息,end就是最晚签离的人的信息。
(后面很多题都有用到temp临时变量来存储读入的每项数据,然后再通过compare来不断更新题目最终结果要求的数据项)

参考题解:

#include<cstdio>
struct person{
	char name[16];
	int hh,mm,ss;
}start,end,temp;
\\a的时间若比b的时间晚则返回true
bool cmp(person a,person b){
	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;
}
void init(){
	end.hh=0;end.mm=0;end.ss=0;\\设置初始签离时间为最早
	start.hh=23;start.mm=59;start.ss=59;\\设置初始签到时间为最晚
}
int main(){
	init();
	int n;
	scanf("%d",&n);
	while(n--){
		scanf("%s %d:%d:%d",temp.name,&temp.hh,&temp.mm,&temp.ss);
		if(!cmp(temp,start))start=temp;
		scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss);
		if(cmp(temp,end))end=temp;
	}
	printf("%s %s\n",start.name,end.name);
	return 0;
} 

后记

初次尝试GuiMiner挖矿

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
大学生参加学科竞赛有着诸多好处,不仅有助于个人综合素质的提升,还能为未来职业发展奠定良好基础。以下是一些分析: 首先,学科竞赛是提高专业知识和技能水平的有效途径。通过参与竞赛,学生不仅能够深入学习相关专业知识,还能够接触到最新的科研成果和技术发展趋势。这有助于拓展学生的学科视野,使其对专业领域有更深刻的理解。在竞赛过程中,学生通常需要解决实际问题,这锻炼了他们独立思考和解决问题的能力。 其次,学科竞赛培养了学生的团队合作精神。许多竞赛项目需要团队协作来完成,这促使学生学会有效地与他人合作、协调分工。在团队合作中,学生们能够学到如何有效沟通、共同制定目标和分工合作,这对于日后进入职场具有重要意义。 此外,学科竞赛是提高学生综合能力的一种途径。竞赛项目通常会涉及到理论知识、实际操作和创新思维等多个方面,要求参赛者具备全面的素质。在竞赛过程中,学生不仅需要展现自己的专业知识,还需要具备创新意识和解决问题的能力。这种全面的综合能力培养对于未来从事各类职业都具有积极作用。 此外,学科竞赛可以为学生提供展示自我、树立信心的机会。通过比赛的舞台,学生有机会展现自己在专业领域的优势,得到他人的认可和赞誉。这对于培养学生的自信心和自我价值感非常重要,有助于他们更加积极主动地投入学习和未来的职业生涯。 最后,学科竞赛对于个人职业发展具有积极的助推作用。在竞赛中脱颖而出的学生通常能够引起企业、研究机构等用人单位的关注。获得竞赛奖项不仅可以作为个人履历的亮点,还可以为进入理想的工作岗位提供有力的支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逝不等琴生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值