pat甲级1006 Sign In and Sign Out
题意:给你n条信息,分别代表n个人去机房的id,和去的时间以及离开的时间,要求谁最早到,谁最晚离开。
分析:送分题,sort+自定义排序即可,用结构体数组模拟。至于题目给的标准时间,分别用时,分,秒变量记录一下再转换一下进行预处理,换算成一个整数值就好了。
1 #include2 #include 3 #include 4 using namespace std; 5 struct node 6 { 7 char id[20]; 8 int start,end; 9 }a[10010]; 10 struct rule1 11 { 12 bool operator()(const node & n1,const node &n2) 13 { 14 return n1.start<n2.start; 15 } 16 }; 17 struct rule2 18 { 19 bool operator()(const node & n1,const node &n2) 20 { 21 return n1.end>n2.end; 22 } 23 }; 24 int main() 25 { 26 int n; 27 while(cin>>n) 28 { 29 memset(a,0,sizeof(a)); 30 int s_h,s_m,s_s,e_h,e_m,e_s; 31 char p; 32 for(int i=0;i ) 33 { 34 cin>>a[i].id; 35 cin>>s_h>>p>>s_m>>p>>s_s; 36 cin>>e_h>>p>>e_m>>p>>e_s; 37 a[i].start=s_h*3600+s_m*60+s_s; 38 a[i].end=e_h*3600+e_m*60+e_s; 39 } 40 sort(a,a+n,rule1()); 41 cout<0].id<<" "; 42 sort(a,a+n,rule2()); 43 cout<0].id<<endl; 44 } 45 return 0; 46 }