A_1006

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

解析:存储下来,遍历就行。也可以不存储,存储都不需要。但是得每次保存earliest和latest数据。

#include <bits/stdc++.h>
using namespace std;
class Sign{
    public:
        string id;
        int in_h;
        int in_m;
        int in_s;
        int out_h;
        int out_m;
        int out_s;
};
int main()
{
    int n, i, earliest = 0, latest = 0;
    cin >> n;
    Sign *s = new Sign[n];
    for(i = 0; i < n; i++){
        cin >> s[i].id;
        scanf("%d:%d:%d %d:%d:%d", &s[i].in_h, &s[i].in_m, &s[i].in_s, 
                &s[i].out_h, &s[i].out_m, &s[i].out_s);
    }
    for(i = 1; i < n; i++)
    {
        if(s[earliest].in_h > s[i].in_h){
            earliest = i;
        }else if(s[earliest].in_h < s[i].in_h){
            continue;
        }else{
            if(s[earliest].in_m > s[i].in_m){
                earliest = i;
            }else if(s[earliest].in_m < s[i].in_m){
                continue;
            }else{
                if(s[earliest].in_s > s[i].in_s){
                    earliest = i;
                }else if(s[earliest].in_s < s[i].in_s){
                    continue;
                }
            }
        }
    }
    for(i = 1; i < n; i++){
        if(s[latest].out_h < s[i].out_h){
            latest = i;
        }else if(s[latest].out_h > s[i].out_h){
            continue;
        }else{
            if(s[latest].out_m < s[i].out_m){
                latest = i;
            }else if(s[latest].out_m > s[i].out_m){
                continue;
            }else{
                if(s[latest].out_s < s[i].out_s){
                    latest = i;
                }else if(s[latest].out_s > s[i].out_s){
                    continue;
                }
            }
        }
    }
    cout << s[earliest].id << " " << s[latest].id;
    return 0;
} 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,141评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,425评论 0 23
  • 下午我姐姐还有姐姐的朋友,带我去东花园看灯展,我们在路上说说笑笑,我们看见有人在湖边钓鱼,有的在花丛中修剪...
    张佳明阅读 1,228评论 0 1
  • 1香蕉皮可以用来擦拭皮鞋、皮衣 香蕉皮可以用来擦拭皮鞋、皮衣、皮制沙发等,有长保皮制品光泽、延长皮制品“寿命”的作...
    皇氏三墳阅读 1,774评论 0 1
  • 本文部分内容来自百度经验和《经络调理和眼部保健》,基于眼部保健知识分享,非商用。内容仅供参考,并受原版权保护。 涉...
    清香雨兰阅读 3,652评论 0 2