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 }
  • 相关阅读:
    纷享销客公司产品能力学习笔记
    有质量的两道面试题
    java项目启动时执行指定方法
    css银行卡号样式
    swiper6使用鼠标滚轮失效退回swiper4即可
    vue-swiper Demo
    vue点击下载图片
    跨域请求发送数据在body里,java后台接收
    跨域,跨服务session获取不到,前后台不会传输Cookie,sessionId不一致
    Windows下 redis命令及配置
  • 原文地址:https://www.cnblogs.com/cdp1591652208/p/9354204.html
Copyright © 2011-2022 走看看