開門人 關門人

開門人 關門人

開門人和關門人

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16160    Accepted Submission(s): 8261
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


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct people{
	char num[50];
	int come;
	int out;
}p[5000];
bool cmp1(people a,people b){
	if(a.come==b.come){
		int t=strcmp(a.num,b.num);
		if(t==-1){
			return true;
		}else return false;
	}else{
		return a.come<b.come;
	}
}
bool cmp2(people a,people b){
	if(a.out==b.out){
		int t=strcmp(a.num,b.num);
		if(t==-1){
			return true;
		}else return false;
		
	}else  return a.out>b.out;
}
int main()
{
	int n,m;
	cin>>n;
	while(n--){
		cin>>m;
		for(int i=0;i<m;i++){
			int h,m,s;
			cin>>p[i].num;
			scanf("%d:%d:%d",&h,&m,&s);
			p[i].come=h*3600+m*60+s;
			scanf("%d:%d:%d",&h,&m,&s);
			p[i].out=h*3600+m*60+s;
		}
		sort(p,p+m,cmp1);
		cout<<p[0].num<<" ";
		sort(p,p+m,cmp2);
		cout<<p[0].num<<endl;
	}
	return 0;
}





發佈了36 篇原創文章 · 獲贊 6 · 訪問量 9758
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章