美文网首页
2020-03-07

2020-03-07

作者: joker_luo | 来源:发表于2020-03-07 21:14 被阅读0次

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`
//本体思路比较简单,就是找谁最早来,谁最晚离开,给出的时间段是来的时间和离开的时间
//来的时间可以当成从零点0分0秒开始,到来的时间的时间段,全部换算成秒,
//来的最早的一定是来的时间总秒数最小的;离开最晚的即离开时间总秒数最大的。 
#include<iostream>
#include<string>
using namespace std;
typedef struct Data{
    string name;
    int beginhour;
    int beginminute;
    int beginsecond;
    int endhour;
    int endmintue;
    int endsecond;
}Data;
int main(){
    Data arr[500];
    int M;
    cin>>M;
    for(int i=0;i<M;++i){
        cin>>arr[i].name;
        scanf("%d:%d:%d",&arr[i].beginhour,&arr[i].beginminute,&arr[i].beginsecond);
        scanf("%d:%d:%d",&arr[i].endhour,&arr[i].endmintue,&arr[i].endsecond);
    }
    //为了进入循环,使unlock的初值为第一个人到的总秒数,方便后续比较,设置一个大于一天的总秒数即可。 
    int unlock=99999999;
    //与上面一样,方便进入循环比较,第一个人离开的总秒数,方便比较,小于0即可。 
    int lock = -1;
    //用于标记i,方便输出名字。  
    int n=0,m=0;
    int data=0;
    int data2=0;
    for(int j=0;j<M;++j){
        data = arr[j].beginhour*3600+arr[j].beginminute*60+arr[j].beginsecond;
        data2 = arr[j].endhour*3600+arr[j].endmintue*60+arr[j].endsecond;
        if(unlock>data){
            unlock = data;
            n = j;
        }
        if(lock<data2){
            lock = data2;
            m = j;
        }
    }
    cout<<arr[n].name<<" "<<arr[m].name;
    return 0;
}

PS:我没学过算法,都是想到怎么做就怎么做,没考虑复杂度的问题,等以后有时间了再去学习最优解吧。

相关文章

  • git notes

    title: git notesdate: 2020-03-07 01:13:12tags: 工具 hexocat...

  • 【漫画优选】斗破苍穹

    简介 状态[连载中] 作者[天蚕土豆 任翔] 更新[2020-03-07] 最新[第834话 海角天涯,两鬓生华(...

  • 观察视角

    中原焦点团队 高艳峰 信阳 网络中级九期 坚持分享第703天 2020-03-07 错过了周四刘友龙老师...

  • 淘书小助手隐私协议

    **生效日期:2020-03-07 ** 淘书(以及以下提到的“我們”,“我們的”或“此應用程序”。)由主體公司提...

  • 每天日常隐私协议

    **生效日期:2020-03-07 ** 每天日常(以及以下提到的“我們”,“我們的”或“此應用程序”。)由主體公...

  • 你喜欢谁就去追,因为——

    2020-03-07 回来了? 我还没来得及给你做饭呢! 女:那我点外卖吧,你吃什么? 我看看哈 女:等我回个信息...

  • 产品创新地图:4个问题逼出成果--1

    编号:研习社2020-03-07 并不是每一篇混沌大学的课程,吴叔都会推荐。但能学习和借鉴,帮助落地的课程...

  • 2020-03-07

    2020-03-07 星期六 一、亿万富翁制造机分享 早上起床照镜子,看着自己的眼睛:美女,早上好!我爱你。吻! ...

  • 看书/《被讨厌的勇气》

    2020-03-07/03-08 昨日由于写推文已经没有多余的精力日更日记了。 忙着写女神节的广告推文。 对了,昨...

  • 读完这本书,让我想去伊朗转转

    2020-03-07 星期六 晴第184段文字 1 之前读过一本书《追风筝的人》。 看后觉得难以抑制内心的波澜,...

网友评论

      本文标题:2020-03-07

      本文链接:https://www.haomeiwen.com/subject/iqqkdhtx.html