当前位置: 代码迷 >> 综合 >> PAT甲级-1006 Sign In and Sign Out (25分)
  详细解决方案

PAT甲级-1006 Sign In and Sign Out (25分)

热度:39   发布时间:2023-09-27 00:06:10.0

点击链接PAT甲级-AC全解汇总

题目:
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

题意:
输入n个人进出的时间 找到进入最早的人和最晚出去的人

我的代码:

#include<bits/stdc++.h>
using namespace std;class Person{
    
public:Person(){
    };~Person(){
    };Person(string name,int a,int b,int c,int d,int e,int f):name(name),in_hh(a),in_mm(b),in_ss(c),out_hh(d),out_mm(e),out_ss(f){
    }string name;int in_hh=99,in_mm,in_ss;int out_hh=0,out_mm,out_ss;bool operator==(Person p){
    this->name=p.name;this->in_hh=p.in_hh;this->in_mm=p.in_mm;this->in_ss=p.in_ss;this->out_hh=p.out_hh;this->out_mm=p.out_mm;this->out_ss=p.out_ss;}bool operator<(Person p){
    if(this->in_hh!=p.in_hh)return this->in_hh<p.in_hh;else if(this->in_mm!=p.in_mm)return this->in_mm<p.in_mm;else return this->in_ss<p.in_ss;}bool operator>(Person p){
    if(this->out_hh!=p.out_hh)return this->out_hh>p.out_hh;else if(this->out_mm!=p.out_mm)return this->out_mm>p.out_mm;else return this->out_ss>p.out_ss;}
};int main()
{
    int N;cin>>N;Person p_in,p_out;for(int i=0;i<N;i++){
    string name;int in_hh,in_mm,in_ss;int out_hh,out_mm,out_ss;cin>>name;scanf("%d:%d:%d %d:%d:%d",&in_hh,&in_mm,&in_ss,&out_hh,&out_mm,&out_ss);Person p(name,in_hh,in_mm,in_ss,out_hh,out_mm,out_ss);if(p<p_in)p_in=p;if(p>p_out)p_out=p;}cout<<p_in.name<<" "<<p_out.name<<endl;return 0;
}
  相关解决方案