PAT 1006 Sign In and Sign Out

1006. Sign In and Sign Out (25)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

Input Specification:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.

Output Specification:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

Sample Input:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

Sample Output:

SC3021234 CS301133

题意是要求你求出最先到的和最后走到

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <map>
#include <strstream>
#include <string>

using namespace std;
struct Node
{
  string s;
  int stime;
  int ltime;
}a[10005];
int n;
int cmp1(Node a,Node b)
{
  return a.stime<b.stime;
}
int cmp2(Node a,Node b)
{
  return a.ltime>b.ltime;
}
int time(int hh,int mm,int ss)
{
  return hh*3600+mm*60+ss;
}
int main()
{
    scanf("%d",&n);
  int h,m,s;
  for(int i=0;i<n;i++)
  {
    cin>>a[i].s;
    scanf("%d:%d:%d",&h,&m,&s);
    a[i].stime=time(h,m,s);
    scanf("%d:%d:%d",&h,&m,&s);
    a[i].ltime=time(h,m,s);
  }
  sort(a,a+n,cmp1);
  cout<<a[0].s<<" ";
  sort(a,a+n,cmp2);
  cout<<a[0].s<<endl;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏算法修养

HDU 5652 India and China Origins(并查集)

India and China Origins Time Limit: 2000/2000 MS (Java/Others)    Memory Limit:...

3287
来自专栏算法修养

HDU 2476 String painter(区间DP)

String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/327...

3468
来自专栏小樱的经验随笔

2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja...

3756
来自专栏ml

HDU----(3294)Girls' research(manacher)

Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/3...

2835
来自专栏HansBug's Lab

3399: [Usaco2009 Mar]Sand Castle城堡

3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MB Subm...

2044
来自专栏算法修养

HDU 5157 Harry and magic string(回文树)

Harry and magic string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

3728
来自专栏ml

HDUOJ---The Moving Points

The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/...

3324
来自专栏听雨堂

加点的心得

加点的一般方法:    Catalog _catalog=MapInfo.Engine.Session.Current.Catalog;    MapInf...

19510
来自专栏算法修养

HOJ 2226&POJ2688 Cleaning Robot(BFS+TSP(状态压缩DP))

Cleaning Robot Time Limit: 1000MS Memory Limit: 65536K Total Submission...

2944
来自专栏小樱的经验随笔

POJ 2209 The King(简单贪心)

The King Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7499...

2834

扫码关注云+社区

领取腾讯云代金券