zoukankan      html  css  js  c++  java
  • PAT 1006 Sign In and Sign Out

    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


    时间限制: 400 ms
    内存限制: 64 MB
    代码长度限制: 16 KB
     

    思路

    结构体排序,使用scanf进行输入处理。
     1 #include <iostream>
     2 #include <string>
     3 #include <stdio.h>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 struct Node
     9 {
    10     string name;
    11     int inH, inM, inS;        //进入的时、分、秒 
    12     int outH, outM, outS;    //出去的时、分、秒 
    13 }node[100000]; 
    14 
    15 bool cmp1(Node a, Node b)
    16 {
    17     if(a.inH != b.inH)
    18         return a.inH < b.inH;
    19     if(a.inM != b.inM)
    20         return a.inM < b.inM;
    21     if(a.inS != b.inS)
    22         return a.inS < b.inS;
    23     return true;
    24 }
    25 
    26 bool cmp2(Node a, Node b)
    27 {
    28     if(a.outH != b.outH)
    29         return a.outH > b.outH;
    30     if(a.outM != b.outM)
    31         return a.outM > b.outM;
    32     if(a.outS != b.outS)
    33         return a.outS > b.outS;
    34     return true;
    35 }
    36 
    37 int main()
    38 {
    39     int m;
    40     cin >> m;
    41     for(int i = 0; i < m; ++i)
    42     {
    43         cin >> node[i].name;
    44         scanf("%d:%d:%d %d:%d:%d", &node[i].inH, &node[i].inM, &node[i].inS, 
    45             &node[i].outH, &node[i].outM, &node[i].outS);
    46     }
    47     
    48     sort(node, node+m, cmp1);
    49     cout << node[0].name << ' ';
    50     sort(node, node+m, cmp2);
    51     cout << node[0].name;
    52     
    53 
    54 
    55     return 0;
    56 }
  • 相关阅读:
    响应者链的事件传递过程
    事件的产生和传递
    UIView不接受触摸事件的三种情况
    利用UIActivityController调用ios系统自带的分享功能,实现微信发布多图的功能
    CALayer
    CATransition-转场动画
    iOS分类、延展和子类的区别
    ios如何普安短图片类型
    使用Google code + SVN进行多人开发
    搭建CppUnit错误总结
  • 原文地址:https://www.cnblogs.com/FengZeng666/p/12577307.html
Copyright © 2011-2022 走看看