1006 Sign In and Sign Out (25分)
#include<iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
using namespace std;
int time_value(int h,int m,int s)
{
return h*3600+m*60+s;
}
int main()
{
int T;
cin>>T;
char first_in[20];
char last_out[20];
int in_time=24*3600;
int out_time=0;
for(int i=0; i<T; i++)
{
char name[20];
cin>>name;
int hour,minute,second;
scanf("%d:%d:%d",&hour,&minute,&second);
int time = time_value(hour,minute,second);
//cout<<time<<endl;
if(time < in_time)
{
strcpy(first_in,name);
in_time = time;
}
scanf("%d:%d:%d",&hour,&minute,&second);
time = time_value(hour,minute,second);
if(time > out_time)
{
strcpy(last_out,name);
out_time = time;
}
}
cout<<first_in<<" "<<last_out;
}

浙公网安备 33010602011771号