题目大意:给出每个员工的签入签出时间,输出签入最早的员工和签出最晚的员工。
开始时定义最早的时间是23:59:59, 最晚的时间是 00:00:00,输入过程中进行更新并记录最早和最晚的员工即可。
AC代码如下:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
using namespace std;
int main()
{
int N;
scanf("%d\n", &N);
string firstTime = "23:59:59", lastTime = "00:00:00", firstPerson, lastPerson;
for (int i = 0; i < N; ++i)
{
char name[20], inTime[20], outTime[20];
scanf("%s%s%s", name, inTime, outTime);
string id = string(name);
string in = string(inTime);
string out = string(outTime);
if(in < firstTime)
{
firstPerson = id;
firstTime = in;
}
if(out > lastTime)
{
lastPerson = id;
lastTime = out;
}
}
printf("%s %s", firstPerson.c_str(), lastPerson.c_str());
return 0;
}