开门人和关门人 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19145 Accepted Submission(s): 9677
Problem Description 每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签 到、签离记录,请根据记录找出当天开门和关门的人。
Input 测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。 每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为
证件号码 签到时间 签离时间
其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。 Output 对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。 注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前, 且没有多人同时签到或者签离的情况。 Sample Input
3 1 ME3021112225321 00:00:00 23:59:59 2 EE301218 08:05:35 20:56:35 MA301134 12:35:45 21:40:42 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40 Sample Output
ME3021112225321 ME3021112225321 EE301218 MA301134 SC3021234 CS301133 Source 浙大计算机研究生复试上机考试-2005年 Recommend JGShining 很水的题 ,但是遇到一个小问题,卡了一个小时 ,就是输入的时候的问题(还不知道原因) 把时间划为整数(秒)比较: wa代码: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct people{
char num[20];
int s,e;
}peo[1010];
int main()
{
int t,n;
cin >> t;
while(t--){
memset(peo,0,sizeof(peo));
cin >> n;
int i,sh,sm,ss,eh,em,es,sx = 3600*24,ex = 0,sy=0,ey=0;
char c;
for(i = 0;i < n;i++){
cin >> peo[i].num >> sh>>c>>sm>>c>>ss >>eh>>c>>em>>c>>es;
peo[i].s = sh*3600+sm*60+ss;
peo[i].e = eh*3600+em*60+ss;
if(peo[i].s < sx){
sy = i;
sx = peo[i].s;
}
if(peo[i].e > ex){
ey = i;
ex = peo[i].e;
}
}
cout << peo[sy].num << ' ' << peo[ey].num << endl;
}
return 0;
} ac代码: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct people{
char num[20];
int s,e;
}peo[1010];
int main()
{
int t,n;
cin >> t;
while(t--){
memset(peo,0,sizeof(peo));
cin >> n;
int i,h,m,s,sx = 3600*24,ex = 0,sy=0,ey=0;
char c;
for(i = 0;i < n;i++){
cin >> peo[i].num >> h>>c>>m>>c>>s;
peo[i].s = h*3600+m*60+s;
if(peo[i].s < sx){
sy = i;
sx = peo[i].s;
}
cin >>h>>c>>m>>c>>s;
peo[i].e = h*3600+m*60+s;
if(peo[i].e > ex){
ey = i;
ex = peo[i].e;
}
}
cout << peo[sy].num << ' ' << peo[ey].num << endl;
}
return 0;
} 将时间看作字符串比较: ac代码: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct people{
char a[20],b[20],c[20];
}peo[1010],p1,p2;
int main()
{
int t,n;
cin >> t;
while(t--){
cin >> n;
int i;
for(i = 0;i < n;i++)
cin >> peo[i].a >> peo[i].b >> peo[i].c;
p1 = p2 = peo[0];
for(i = 1;i < n;i++){
p1 = (strcmp(p1.b,peo[i].b)>0?peo[i]:p1);
p2 = (strcmp(p2.c,peo[i].c)>0?p2:peo[i]);
}
cout << p1.a << ' ' << p2.a << endl;
}
return 0;
} |