题解 | #开门人和关门人#C++,可以通过字典序直接对比

开门人和关门人

https://www.nowcoder.com/practice/a4b37b53a44d454ab0834e1517983215

#include <iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int main() {
    int n;
    while (scanf("%d",&n)!=EOF&&n>0) {
        getchar();

        string early="99:99:99";//用于对比早班时间
        string earlypeople="";//用于保存开门人
        string lately="00:00:00";//用于对比晚班时间
        string latepeople="";//用于保存关门人

        for(int i=0;i<n;i++){
            string s;
            getline(cin,s);
            //切记每个字符串后面有个换行符需要读取,我在这里报错纠结了很久
            int first=s.find(' ');
            //查找号码和日期之间的空格
            string name=s.substr(0,first);
            string front_time=s.substr(first+1,8);
            //前面的日期
            string rear_time=s.substr(first+10);
			//后面的日期
            if(front_time<early){
                early=front_time;
                earlypeople=name;
            }
                
            if(rear_time>lately){
				latepeople=name;
                lately=rear_time;
            }
                
        }
        cout<<earlypeople<<" ";
        cout<<latepeople<<endl;

    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

04-30 21:35
已编辑
长安大学 C++
晓沐咕咕咕:评论区没被女朋友好好对待过的计小将可真多。觉得可惜可以理解,毕竟一线大厂sp。但是骂楼主糊涂的大可不必,说什么会被社会毒打更是丢人。女朋友体制内生活有保障,读研女朋友还供着,都准备订婚了人家两情相悦,二线本地以后两口子日子美滋滋,哪轮到你一个一线城市房子都买不起的996清高计小将在这说人家傻😅
点赞 评论 收藏
分享
04-14 20:10
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务