1.题目介绍
2.考察点,难度
字符串处理类,string转int,map容器存储,难度易
3.解题代码
string本身存在比较函数,可以直接用string来做比较而不需要转换成int。
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("D:\\PAT\\Clion\\in.txt","r",stdin);
int N;
string in="24:00:00", out="00:00:00",iid="",oid="";
unordered_map<string,string> I,O;
cin>>N;
for(int i=0;i<N;i++){
string id,a,b;
cin>>id>>a>>b;
I.insert({id,a});
O.insert({id,b});
}
for(auto s:I){
int first = stod(s.second.substr(0,2))-stod(in.substr(0,2));
int second = stod(s.second.substr(3,2))-stod(in.substr(3,2));
int third = stod(s.second.substr(6,2))-stod(in.substr(6,2));
if(first>0 || (first==0 && second>0) || (first==0 && second==0 && third>0)){
continue;
}
else{
in=s.second;
iid=s.first;
}
}
for(auto s:O){
int first = stod(s.second.substr(0,2))-stod(out.substr(0,2));
int second = stod(s.second.substr(3,2))-stod(out.substr(3,2));
int third = stod(s.second.substr(6,2))-stod(out.substr(6,2));
if(first<0 || (first==0 && second<0) || (first==0 && second==0 && third<0)){
continue;
}
else{
out=s.second;
oid=s.first;
}
}
cout<<iid<<" "<<oid<<endl;
return 0;
}
4.原题地址
https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928