zoukankan      html  css  js  c++  java
  • PAT (Advanced Level) Practice 1006 Sign In and Sign Out (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 <algorithm>
     3 #include <string>
     4 #include <cstring>
     5 #include <cstdio>
     6 using namespace std;
     7 
     8 int n;
     9 struct Node
    10 {
    11     //char s1[50];
    12     //char s2[50];
    13     //char s3[50];
    14     string s1,s2,s3;
    15 }a[100];
    16 int cmp1(Node x,Node y)
    17 {
    18     return x.s2<y.s2; 
    19 }
    20 int cmp2(Node x,Node y)
    21 {
    22     return x.s3<y.s3;
    23 }
    24 int main()
    25 {
    26     while(cin>>n){
    27         for(int i=0;i<n;i++){
    28             cin>>a[i].s1>>a[i].s2>>a[i].s3;
    29         }
    30         string str1,str2;
    31         sort(a,a+n,cmp1);
    32         str1=a[0].s1;
    33         sort(a,a+n,cmp2);
    34         str2=a[n-1].s1;
    35         cout<<str1<<" "<<str2<<endl;
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    shell 远程调用脚本
    Shell 特殊符号
    Centos 7 安全加固命令行
    unix2dos
    这都是啥啥啥
    发现一个识图比较厉害的网站
    Java 中用正则表达式修改 Email 地址
    PHP 7.0 中各种 Hash 速度比较
    利用create_ap软件创建无线AP
    &#129418; 自用Firefox和AdBlockPlus黑白名单
  • 原文地址:https://www.cnblogs.com/wydxry/p/11053195.html
Copyright © 2011-2022 走看看