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

    https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928

    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

    时间复杂度:$O(N)$

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int N;
    
    struct Students {
        char name[50];
        int sh, sm, ss;
        int eh, em, es;
        long long sTime, eTime;
    }students[maxn];
    
    int main() {
        scanf("%d", &N);
        bool flag = true;
        for(int i = 1; i <= N; i ++) {
            scanf("%s %d:%d:%d %d:%d:%d", students[i].name, &students[i].sh, &students[i].sm,
                  &students[i].ss, &students[i].eh, &students[i].em, &students[i].es);
            students[i].sTime = students[i].sh * 3600 + students[i].sm * 60 + students[i].ss;
            students[i].eTime = students[i].eh * 3600 + students[i].em * 60 + students[i].es;
            if(students[i].sTime > students[i].eTime)
                flag = false;
        }
    
        int temp1, temp2;
        long long minn = students[1].sTime, maxx = students[1].eTime;
        for(int i = 1; i <= N; i ++) {
            if(flag) {
                if(students[i].sTime <= minn) {
                    minn = students[i].sTime;
                    temp1 = i;
                }
                if(students[i].eTime >= maxx) {
                    maxx = students[i].eTime;
                    temp2 = i;
                }
            }
        }
    
        printf("%s %s
    ", students[temp1].name, students[temp2].name);
    
        return 0;
    }
    

      

  • 相关阅读:
    [转]VSTO Office二次开发RibbonX代码结构
    [转]VSTO+WinForm+WebService+WCF+WPF示例
    Ext Js简单Data Store创建及使用
    Web页面常用文件格式文件流的输出
    VSTO Office二次开发PPTRibbonX命令操作及对象添加
    VSTO Office二次开发键盘鼠标钩子使用整理
    VSTO Office二次开发对PPT自定义任务窗格测试
    VSTO Office二次开发对PowerPoint功能简单测试
    Ext Js简单Tree创建及其异步加载
    VB获取和更改文件属性
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9652323.html
Copyright © 2011-2022 走看看