http://ac.jobdu.com/problem.php?pid=1013

来源:互联网 发布:查士丁尼瘟疫 知乎 编辑:程序博客网 时间:2024/05/01 09:53
题目描述:
    每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签到、签离记录,请根据记录找出当天开门和关门的人。
输入:

    测试输入的第一行给出记录的总天数N ( N> 0 ),下面列出了N天的记录。 
    每天的记录在第一行给出记录的条目数M (M > 0 ),下面是M行,每行的格式为 

    证件号码 签到时间 签离时间 

    其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。

输出:

    对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。 
    注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,且没有多人同时签到或者签离的情况。

样例输入:
31ME3021112225321 00:00:00 23:59:592EE301218 08:05:35 20:56:35MA301134 12:35:45 21:40:423CS301111 15:30:28 17:00:10SC3021234 08:00:00 11:25:25CS301133 21:45:00 21:58:40
样例输出:
ME3021112225321 ME3021112225321EE301218 MA301134SC3021234 CS301133

[cpp] view plaincopy
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<memory.h>  
  4. #include<cstdlib>  
  5. using namespace std;  
  6. struct Node{  
  7.     char str[16];  
  8.     int h, m, s;  
  9.     bool operator <(const Node &b)const{  
  10.         if(h!=b.h)  
  11.             return h<b.h;  
  12.         if(m!=b.m)  
  13.             return m<b.m;  
  14.         return s<b.s;  
  15.     }  
  16.     bool operator >(const Node &b)const{  
  17.         if(h!=b.h)  
  18.             return h>b.h;  
  19.         if(m!=b.m)  
  20.             return m>b.m;  
  21.         return s>b.s;  
  22.     }  
  23. };  
  24. Node nodes[2];  
  25.   
  26. int main(){  
  27.     //freopen("in.txt", "r", stdin);  
  28.   
  29.     int n, m;  
  30.     char s[20];  
  31.     while(cin>>n){  
  32.         for(int i=0;i<n;++i){  
  33.             cin>>m;  
  34.             nodes[0].h = 1000;  
  35.             nodes[1].h = -1000;  
  36.             while(m--){  
  37.                 Node node;  
  38.                 cin>>node.str;  
  39.                 cin>>node.h;  
  40.                 getchar();  
  41.                 cin>>node.m;  
  42.                 getchar();  
  43.                 cin>>node.s;  
  44.   
  45.                 if(node<nodes[0])  
  46.                     nodes[0] = node;  
  47.   
  48.                 cin>>node.h;  
  49.                 getchar();  
  50.                 cin>>node.m;  
  51.                 getchar();  
  52.                 cin>>node.s;  
  53.   
  54.                 if(node>nodes[1])  
  55.                     nodes[1] = node;  
  56.   
  57.             }  
  58.             cout<<nodes[0].str<<" "<<nodes[1].str<<endl;  
  59.   
  60.         }  
  61.     }  
  62.     //fclose(stdin);  
  63.     return 0;  
  64. }  
原创粉丝点击