zoukankan      html  css  js  c++  java
  • PAT 甲级 1006 Sign In and Sign Out (25)(25 分)

    1006 Sign In and Sign Out (25)(25 分)

    At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

    Input Specification:

    Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

    ID_number Sign_in_time Sign_out_time
    

    where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.

    Output Specification:

    For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

    Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

    Sample Input:

    3
    CS301111 15:30:28 17:00:10
    SC3021234 08:00:00 11:25:25
    CS301133 21:45:00 21:58:40
    

    Sample Output:

    SC3021234 CS301133
     1 #include<iostream>
     2 #include<string>
     3 
     4 using namespace std;
     5 
     6 struct record
     7 {
     8     string idNumber;
     9     int comeTime;
    10     int leaveTime;
    11     
    12     record()
    13     {
    14         comeTime=0;
    15         leaveTime=0;
    16         idNumber = " ";
    17     }
    18     
    19     //将字符串时间变为整型时间 
    20     void init(string str1,string str2,string str3)
    21     {
    22         idNumber = str1;
    23         
    24         for(int i=0;i<8;++i)
    25         {
    26             if(i!=2 && i!=5)
    27             {
    28                 comeTime = 10*comeTime+str2[i]-48;
    29                 leaveTime = 10*leaveTime+str3[i]-48; 
    30             }
    31         }
    32     }
    33 };
    34 
    35 int main()
    36 {
    37   int n,min=240000,max=0;
    38   string str1,str2,str3,firstID,lastID;
    39   
    40   cin>>n;
    41   
    42   record *p =new record[n];
    43   
    44   for(int i=0;i<n;++i)
    45   {
    46       cin>>str1>>str2>>str3;
    47       
    48       p[i].init(str1,str2,str3);
    49       
    50       if(p[i].comeTime < min)
    51       {
    52           firstID=p[i].idNumber;
    53           min = p[i].comeTime;
    54     }
    55           
    56       if(p[i].leaveTime > max)
    57       {
    58           lastID = p[i].idNumber;
    59           max = p[i].leaveTime;
    60     }
    61   }
    62   
    63   cout<<firstID<<" "<<lastID<<endl;
    64   
    65   delete[] p;
    66   
    67   return 0;
    68 }
  • 相关阅读:
    AES算法,DES算法,RSA算法JAVA实现
    spring官方学习地址
    逐步理解SpringMVC
    sublime前端开发工具常用技巧
    谈谈关键字new
    关于mybatisgenerator的问题
    AOPjdk动态代理的思考
    关于java解析xml文件出现的问题
    Java注解
    git向码云上传代码总结
  • 原文地址:https://www.cnblogs.com/cdp1591652208/p/9354204.html
Copyright © 2011-2022 走看看