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 }
  • 相关阅读:
    「B/S端开发」DevExtreme初级入门教程 Vue篇入门指南
    界面控件DevExpress WinForm MVVM命令讲解(三)
    界面控件DevExpress WPF入门级教程 调用表达式编辑器
    界面控件Telerik UI for WinForms入门教程 Telerik Upgrade API Analyzer
    响应式UI部件DevExtreme正式发布v21.2.4
    python枚举之Enum模块
    MessageBox的用法
    dotnet中的时间差
    在C#中API函数的调用
    关于C#中timer类 在C#里关于定时器类就有3个
  • 原文地址:https://www.cnblogs.com/shixinzei/p/11053195.html
Copyright © 2011-2022 走看看