题解 | #开门人和关门人#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")

全部评论

相关推荐

有没有友友知道hr面会问什么我应该反问什么?还有如何防止hr套话啊?还有应该如果催hr推进快一点#字节#OPPO#hr面
牛客989988346号:职业规划,优缺点,为什么选择这个岗,对应聘公司产品的了解和满意度,如果让你改进公司产品你会怎么做,对ai(新技术)的了解,有无其他offer,什么时候能到岗
点赞 评论 收藏
分享
小明lll:不是哥们我以为驾照是段子呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务