PAT (Advanced Level) Practice 1006 Sign In and Sign Out (C语言) (PTA)

在这里插入图片描述

#include<stdio.h>

int main(){
	
	int M;
	scanf("%d",&M);
	
	typedef struct{
		char id[16];
		int SH[2];
		int SM[2];
		int SS[2];
		int EH[2];
		int EM[2];
		int ES[2];
	}data;
	
	data p[1000];
	int i=0;
	while(M!=0){
		scanf("%s",p[i].id);
		scanf("%02d:%02d:%02d",&p[i].SH,&p[i].SM,&p[i].SS);
		scanf("%02d:%02d:%02d",&p[i].EH,&p[i].EM,&p[i].ES);
		M--;
		i++;
	}
	
	int firstinHH=24;
	int lastoutHH=0;
	int firstinMM=60;
	int lastoutMM=0;
	int firstinSS=60;
	int lastoutSS=0;
	int inpeople=0;
	int outpeople=0;
		
	M=i-1;
	for(; (M+1)!=0; M--){
		if(*p[M].SH<firstinHH){
			firstinHH=*p[M].SH;
			inpeople=M;
		}else if(*p[M].SH==firstinHH){
			if(*p[M].SM<firstinMM){
				firstinMM=*p[M].SM;
				inpeople=M;
			}else if(*p[M].SM==firstinMM){
				if(*p[M].SS<firstinSS){
					firstinSS=*p[M].SS;
					inpeople=M;
				}
			}
		}
		if(*p[M].EH>lastoutHH){
			lastoutHH=*p[M].EH;
			outpeople=M;
		}else if(*p[M].EH==lastoutHH){
			if(*p[M].EM>lastoutMM){
				lastoutMM=*p[M].EM;
				outpeople=M;
			}else if(*p[M].EM==lastoutMM){
				if(*p[M].ES>lastoutSS){
					lastoutSS=*p[M].ES;
					outpeople=M;
				}
			}
		}
	}
	
	printf("%s %s",p[inpeople].id,p[outpeople].id);
	
	return 0;
}

想法是构建一个structure数组,储存每个人的信息,比较时从小时开始,若相等则考虑分钟,再相等则考虑秒。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值