1006 Sign In and Sign Out (25 分)
思路
查找时间最早最晚元素进行打卡,
使用C++的string类型和C语言的scanf输入可以轻松处理本题的输入输出。
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string id;
scanf("%d",&n);
string signin_id ="";
string signout_id ="";
int h1=24,c1=0,s1=0,h2=0,c2=0,s2=0;
int tmp1,tmp2,tmp3;
for (int i =0;i<n;i++)
{
int flag = 0 ;
cin>>id;
scanf("%d:%d:%d",&tmp1,&tmp2,&tmp3);
if(tmp1< h1)
flag =1;
else if(tmp1 == h1)
{
if(tmp2< c1)
flag =1;
else if (tmp2== c1)
if(tmp3< s1)
flag =1;
}
if(flag)
{
signin_id = id;
h1 = tmp1;
c1 = tmp2;
s1 = tmp3;
}
flag = 0 ;
scanf("%d:%d:%d",&tmp1,&tmp2,&tmp3);
if(tmp1> h2)
flag =1;
else if(tmp1 == h2)
{
if(tmp2> c2)
flag =1;
else if (tmp2== c2)
if(tmp3> s2)
flag =1;
}
if(flag)
{
signout_id = id;
h2 = tmp1;
c2 = tmp2;
s2 = tmp3;
}
}
cout<<signin_id<<' '<<signout_id;
}