PAT 1006 Sign In and Sign Out

在这里插入图片描述

思路

每输入一组值,就更新open_time,close_time

代码

#include<iostream>
using namespace std;

int main()
{
    string open_id,open_time;
    string close_id,close_time;
    
    int m;
    cin>>m;
    
    for(int i = 0; i < m; i++)
    {
        string id,in_time,out_time;
        cin>>id>>in_time>>out_time;
        if(i == 0 || in_time < open_time)
        {
            open_id = id;
            open_time = in_time;
        }
        if(i == 0 || out_time > close_time)
        {
            close_id = id;
            close_time = out_time;
        }
    }
    
    cout<<open_id<<' '<<close_id;
    return 0;
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐