PAT(甲级)1006. Sign In and Sign Out

本文提供了一个PAT-A 1006题目的解答代码,该题旨在找出最早和最晚打卡记录。使用C++实现,通过读取员工ID及两次打卡时间来确定最早和最晚的时间记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:https://www.patest.cn/contests/pat-a-practise/1006

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct per{
     char id[16];
	 int h,m,s;
}temp,late,early;
bool later(per a,per b)
{
	if(a.h!=b.h) return a.h>b.h;
	if(a.m!=b.m) return a.m>b.m;
	return a.s>b.s;

}
int main()
{ 
    int m;
	scanf("%d",&m);
	early.h=24,early.m=60,early.s=60;
	late.h=0,late.m=0,late.s=0;
	while(m--)
	{
		scanf("%s %d:%d:%d",&temp.id,&temp.h,&temp.m,&temp.s);
		if(later(temp,early)==false)  early =temp;
		scanf("%d:%d:%d",&temp.h,&temp.m,&temp.s);
		if(later(temp,late)==true) late=temp;
	}
	printf("%s %s",early.id,late.id);
	system("pause");
}				 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值