【PAT甲级】【C++】1006. Sign In and Sign Out (25)

本文介绍了一个使用C++编写的程序,该程序能够记录人员的进入和离开时间,并找出最早进入及最晚离开的人。通过定义结构体来存储ID和个人的进出时间,并利用输入输出操作实现数据的读取与显示。

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

#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 100000
using namespace std;
struct node
{
	char id[15];
	int in;
	int out;
}recode[N];
int main()
{
	int m,i=0,n;
	int h1,h2,m1,m2,s1,s2;
	struct node temp_in,temp_out;
	scanf("%d",&m);
	n=m;//此处复制m是为了后面for循环用的条件,不然while结束m=0无界限可用
	while(m--)
	{
		scanf("%s",&recode[i].id);
		scanf("%d%*c%d%*c%d",&h1,&m1,&s1);//%*c跳过一个字符
		scanf("%d%*c%d%*c%d",&h2,&m2,&s2);
		recode[i].in=h1*3600+m1*60+s1;
		recode[i].out=h2*3600+m2*60+s2;
		i++;

	}
	temp_in=temp_out=recode[0];
	for(i=0;i<n;i++)
	{
		if(recode[i].in<temp_in.in)
			temp_in=recode[i];
		if(recode[i].out>temp_out.out)
			temp_out=recode[i];
	}
	printf("%s %s\n",temp_in.id,temp_out.id);
	return 0;
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值