http://acm.hdu.edu.cn/showproblem.php?pid=1234
记录这个题再次记住,不能用time这个名字命名变量。要不然会出现编译错误。。
还有这次写用了运算符重载,记录一下格式吧。
#include <iostream>
#include <string>
using namespace std;
#define N 105
struct sj{
int h,m,s;
};
struct record_node{
string s;
sj in,out;
};
record_node records[N];
bool operator>(sj a,sj b){
if (a.h>b.h)
return true;
else if (a.h==b.h&&a.m>b.m)
return true;
else if (a.h==b.h&&a.m==b.m&&a.s>b.s)
return true;
return false;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("1234in.txt","r",stdin);
#endif
int m,n,i;
string first,last;
sj min,max;
scanf("%d",&m);
while (m--){
scanf("%d",&n);
for (i=0;i<n;i++){
cin>>records[i].s;
scanf("%d:%d:%d %d:%d:%d",&records[i].in.h,&records[i].in.m,&records[i].in.s,&records[i].out.h,&records[i].out.m,&records[i].out.s);
}
first=last=records[0].s;
min=records[0].in;
max=records[0].out;
for (i=1;i<n;i++){
if (min>records[i].in){
min=records[i].in;
first=records[i].s;
}
if (records[i].out>max){
max=records[i].out;
last=records[i].s;
}
}
cout<<first<<' '<<last<<endl;
}
return 0;
}
本文提供了一道 HDU 1234 编程题的解答思路,通过使用 C++ 实现了选手入场和出场时间的记录,并通过自定义运算符重载比较时间先后顺序,最终找出最早入场和最晚离场的选手。
379

被折叠的 条评论
为什么被折叠?



