PAT 甲级 1006 PAT Ranking 个人错误总结

这个题我没有想到好的算法,用的是排序,结果编译器过了oj没过编译。。。后来发现是用了一个结构体名叫time。
1.time不可做结构体名。
2.按照权重判断可以这样写

if(a1!=b1) return a1>b1;
if(a2!=b2) return a2>b2;

3.柳神的方法更好,因为是时间,可以直接算成秒的格式,快多了。
ac代码(参考晴神)

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

struct tim{
	int h;
	int min;
	int sec;
	char id[20];
}in,out,temp;
bool cmp(tim a,tim b){
	if(a.h>b.h) return true;
	else if(a.h==b.h&&a.min>b.min) return true;
	else if(a.h==b.h&&a.min==b.min&&a.sec>b.sec) return true;
	else return false;
}
void set(tim &a,tim &b){
	a.h=b.h;
	for(int i=0;i<15;i++) a.id[i]=b.id[i];
	a.min=b.min;
	a.sec=b.sec;
}
int main(){
	int N;
	scanf("%d",&N);
	in.h=25;
	out.h=-1;
	for(int i=0;i<N;i++){
		scanf("%s %d:%d:%d",&temp.id,&temp.h,&temp.min,&temp.sec);
		if(!cmp(temp,in)) set(in,temp);
		scanf("%d:%d:%d",&temp.h,&temp.min,&temp.sec);
		if(cmp(temp,out)) set(out,temp);
	}
	printf("%s %s\n",in.id,out.id);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值