1006 Sign In and Sign Out (25 分)

版本2

两次排序

#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm> 
#include <unordered_set>
#include <unordered_map>
#include <map>
using namespace std;
const int N = 1e5+5;
struct node{
	string id, in, out;
}E[N];
bool cmp1(node a, node b){
	return a.in < b.in;
}
bool cmp2(node a, node b){
	return a.out > b.out;
}
int main(){
	int n;
	cin>>n;
	string id, in, out;
	for(int i = 0; i < n; i++){
		cin>>E[i].id>>E[i].in>>E[i].out;
	}
	sort(E, E+n, cmp1);
	cout<<E[0].id<<" ";
	sort(E, E+n, cmp2);
	cout<<E[0].id<<endl;
	return 0;
}

版本1

简单的排序

#include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn=1e5+5;
using namespace std;
struct node{
	char name[20];
	int inh,inm,ins;
	int outh,outm,outs;
}Node[maxn];
bool cmp1(node a,node b){
	if(a.inh!=b.inh) return a.inh <b.inh;
	else if(a.inm!=b.inm) return a.inm < b.inm;
	else return a.ins < b.ins;
}

bool cmp2(node a,node b){
	if(a.outh!=b.outh) return a.outh > b.outh;
	else if(a.outm!=b.outm) return a.outm > b.outm;
	else return a.outs > b.outs;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s %d:%d:%d %d:%d:%d",Node[i].name,&Node[i].inh,&Node[i].inm,&Node[i].ins,&Node[i].outh,&Node[i].outm,&Node[i].outs);
	}
	sort(Node,Node+n,cmp1);
	printf("%s ",Node[0].name);
	sort(Node,Node+n,cmp2);
	printf("%s\n",Node[0].name);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值