[PAT]1006. Sign In and Sign Out (25)

来源:互联网 发布:房屋租赁哪个软件 编辑:程序博客网 时间:2024/04/28 07:04

题目

这里写图片描述

简单来说就是,输入某个id,以及对应的来的时间,和走的时间,找出最早来的人和最晚走的人,输出他们的id

思路

  1. 时间的判断可以统一换算成秒来比较大小
  2. 记录峰值的id和时间,每次读取的时候更新,最后输出即可

代码

#include <stdio.h>#include <iostream>#include <cstring>using namespace std;int main(){    int n;    string s;    int h1,h2,m1,m2,s1,s2,t1,t2;    char no;    string ins,outs;    int intm=0,outm=0;    cin>>n;    for(int i=0;i<n;i++){        cin>>s>>h1>>no>>m1>>no>>s1>>h2>>no>>m2>>no>>s2;        t1=h1*3600+m1*60+s1;        t2=h2*3600+m2*60+s2;        if(i==0){            ins=s;            outs=s;            intm=t1;            outm=t2;            continue;        }        if(t1<intm){            intm=t1;            ins=s;        }        if(t2>outm){            outm=t2;            outs=s;        }    }    cout<<ins<<" "<<outs<<endl;    return 0;}
0 0
原创粉丝点击