题目
code
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct timel{
char id[20];
int HH;
int MM;
int SS;
}Time_in,Time_out,Temp1,Temp2;
bool Less(struct timel temp1,struct timel temp2)
{
if(temp1.HH!=temp2.HH) return temp1.HH<temp2.HH;
else if (temp1.MM!=temp2.MM) return temp1.MM<temp2.MM;
else return temp1.SS<temp2.SS;
}
bool More(struct timel temp1,struct timel temp2)
{
if(temp1.HH!=temp2.HH) return temp1.HH>temp2.HH;
else if (temp1.MM!=temp2.MM) return temp1.MM>temp2.MM;
else return temp1.SS>temp2.SS;
}
void init(){
Time_in.HH=24;
Time_out.HH=00;
Time_in.MM=Time_in.SS=59;
Time_out.MM=Time_out.SS=00;
}
int main(){
init();
int m;
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%s%d:%d:%d%d:%d:%d",Temp1.id,&Temp1.HH,&Temp1.MM,&Temp1.SS,&Temp2.HH,&Temp2.MM,&Temp2.SS);
strcpy(Temp2.id, Temp1.id);
if(Less(Temp1,Time_in))
Time_in=Temp1;
if(More(Temp2,Time_out))
Time_out=Temp2;
}
printf("%s %s",Time_in.id,Time_out.id);
return 0;
}
总结
- bool 排序
if -else if- else
- 结构体一开始在比较时没有思考清楚,到底用2个temp 还是一个temp 所以中间结构体里面写乱了,其实temp可只用一个
- 头文件 c++用 #include 而不是string