请根据记录找出当天开门和关门的人。
Sample Input:
3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40Sample Output:
SC3021234 CS301133
#include <iostream>
#include <string>
using namespace std;
int main()
{
int M;
cin>>M;
int Entertime = -1;
int Leavetime = -1;
string EnterID,LeaveID;
while (M--)
{
string str;
int t1,t2,t3,t4,t5,t6;
char c;
cin>>str>>t1>>c>>t2>>c>>t3>>t4>>c>>t5>>c>>t6;
int time1 = t1*3600 + t2*60 + t3;
int time2 = t4*3600 + t5*60 + t6;
if (time1 < Entertime || Entertime == -1)
{
EnterID = str;
Entertime = time1;
}
if (time2 > Leavetime || Leavetime == -1)
{
LeaveID = str;
Leavetime = time2;
}
}
cout<<EnterID<<" "<<LeaveID;
return 0;
}
本文介绍了一个简单的C++程序,该程序用于确定在一系列记录中最早进入和最晚离开的人的ID。通过对输入的时间进行解析和比较,程序能够找到最早进入时间和最晚离开时间,并输出对应的ID。
993

被折叠的 条评论
为什么被折叠?



