A1006

AC第一版

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;
typedef struct Person{      //数字可以整型输入
 	char id[16];
	int inh;
	int inm;
	int ins;
	int outh;
	int outm;
	int outs;
}person;
person p[100000];
int main(){
	#ifdef ONLINE_JUDGE
	#else
		freopen("1.txt","r",stdin);
	#endif
	int m,rep=0,inh,inm,ins,outh,outm,outs,minIndex=0,maxIndex=0;
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%s %d:%d:%d %d:%d:%d",p[i].id,&p[i].inh,&p[i].inm,&p[i].ins,&p[i].outh,&p[i].outm,&p[i].outs);  //地址符容易漏
	}
	inh=p[0].inh,inm=p[0].inm,ins=p[0].ins;
	outh=p[0].outh,outm=p[0].outm,outs=p[0].outs;
	for(int i=1;i<m;i++){
		if(inh>p[i].inh){
			inh=p[i].inh;
			minIndex=i;
		}else if(inh==p[i].inh){
			if(inm>p[i].inm){
				inm=p[i].inm;
				minIndex=i;
			}else if(inm==p[i].inm){
				if(ins>p[i].ins){
					ins=p[i].ins;
					minIndex=i;
				}
			}
		}
		if(outh<p[i].outh){
			outh=p[i].outh;
			maxIndex=i;
		}else if(outh==p[i].outh){
			if(outm>p[i].outm){
				outm=p[i].outm;
				maxIndex=i;
			}else if(outm==p[i].outm){
				if(outs>p[i].outs){
					outs=p[i].outs;
					maxIndex=i;
				}
			}
		}
	}
	string in,out;
	in=p[minIndex].id;
	out=p[maxIndex].id;
	cout<<in;
	printf(" ");
	cout<<out;
	return 0;
}

算法笔记

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;
struct pnode{
	char id[16];
	int h;
	int m;
	int s;
}temp,ans1,ans2;
bool compare(pnode temp,pnode ans){                //值得学习的比较方式,优雅
	if(temp.h!=ans.h)return temp.h>ans.h;
	else if(temp.m!=ans.m)return temp.m>ans.m;
	else return temp.s>ans.s;
}
int main(){
	#ifdef ONLINE_JUDGE
	#else
		freopen("1.txt","r",stdin);
	#endif
	int m;
	scanf("%d",&m);
	ans1.h=23;
	for(int i=0;i<m;i++){
		scanf("%s %d:%d:%d",temp.id,&temp.h,&temp.m,&temp.s);
		if(!compare(temp,ans1))ans1=temp;
		scanf("%d:%d:%d",&temp.h,&temp.m,&temp.s);
		if(compare(temp,ans2))ans2=temp;
	}
	/*string a1,a2;     //多此一举了,忘了字符数组输出方式
	a1=ans1.id;
	a2=ans2.id;
	cout<<a1;
	printf(" ");
	cout<<a2;*/
	printf("%s %s",ans1.id,ans2.id);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值