• 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 }
  • 相关阅读:
    InputStream,String相互转化
    HttpGet
    MySQL重复数据
    JS获取地址栏参数的方法
    Java解析采集模块
    按键精灵多机型定时秒杀综合版提交脚本
    按键精灵手机版监控像素变换点击脚本
    按键精灵手机版定时点击脚本
    按键精灵获取系统时间定时点击
    window时间服务器 国内可用
  • 原文地址:https://www.cnblogs.com/shixinzei/p/11053195.html
Copyright © 2020-2023  润新知