1006 Sign In and Sign Out (25 分)
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
题目分析:给定数据排序 ,直接利用vector对结构体排序 将比较函数重写就可以了
注意sort中比较函数 返回true是不交换的 鉴于现在我水平较低 之后会尝试分析 源码的(大概
#include<iostream>
#include<string>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
#define MaxNum 1
typedef struct Node {
string ID_numebr;
string Sign_in_time;
string Sign_out_time;
}S;
typedef struct Time {
int H;
int M;
int S;
}T;
T t1, t2;
int Atoi(string str, int i, int j)
{
int num = ;
while (i<j)
{
num = num * + str[i] - '';
i++;
}
return num;
}
bool comp2(const S& a, const S& b)
{ t1.H = Atoi(a.Sign_out_time, , );
t1.M = Atoi(a.Sign_out_time, , );
t1.S = Atoi(a.Sign_out_time, , );
t2.H = Atoi(b.Sign_out_time, , );
t2.M = Atoi(b.Sign_out_time, , );
t2.S = Atoi(b.Sign_out_time, , );
if (t1.H > t2.H)
return true;
else if (t1.H == t2.H && t1.M > t2.M)
return true;
else if (t1.M == t2.M && t1.S > t2.S)
return true;
else
return false;
} bool comp1(const S& a, const S& b)
{ t1.H = Atoi(a.Sign_in_time, , );
t1.M = Atoi(a.Sign_in_time, , );
t1.S = Atoi(a.Sign_in_time, , );
t2.H = Atoi(b.Sign_in_time, , );
t2.M = Atoi(b.Sign_in_time, , );
t2.S = Atoi(b.Sign_in_time, , );
if (t1.H < t2.H)
return true;
else if (t1.H == t2.H && t1.M < t2.M)
return true;
else if (t1.M == t2.M && t1.S < t2.S)
return true;
else
return false;
} int main()
{
vector<Node> N;
S s;
int n;
cin >> n;
for (int i = ; i < n; i++)
{
cin >> s.ID_numebr >> s.Sign_in_time >> s.Sign_out_time;
N.push_back(s);
}
sort(N.begin(), N.end(), comp1);
cout << N[].ID_numebr<<" ";
sort(N.begin(), N.end(), comp2);
cout << N[].ID_numebr;
return ;
}
1006 Sign In and Sign Out (25 分)的更多相关文章
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- 1006 Sign In and Sign Out (25 分)
1006 Sign In and Sign Out (25 分) At the beginning of every day, the first person who signs in the co ...
- 1006 Sign In and Sign Out (25)(25 分)思路:普通的时间比较题。。。
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- pat 1006 Sign In and Sign Out(25 分)
1006 Sign In and Sign Out(25 分) At the beginning of every day, the first person who signs in the com ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642
PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...
- PAT甲 1006. Sign In and Sign Out (25) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- pat1006. Sign In and Sign Out (25)
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PTA (Advanced Level) 1006 Sign In and Sign Out
Sign In and Sign Out At the beginning of every day, the first person who signs in the computer room ...
- PAT甲级——1006 Sign In and Sign Out
PATA1006 Sign In and Sign Out At the beginning of every day, the first person who signs in the compu ...
- PAT Sign In and Sign Out[非常简单]
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
随机推荐
- Kubernetes Jenkins动态创建Slave
目录 0.前言 1.Jenkins部署 2.配置jenkins动态slave 3.dubbo服务构建 3.1.制作dubbo镜像底包 3.2.制作slave基础镜像 3.2.1.Maven镜像 3.2 ...
- Java基础面试系列(一)
Java基础面试总结(一) 1. 面向对象和面向过程的区别 面向过程 面向对象 性能 高于面向对象 类加载的时候需要实例化,比较消耗资源 三易(易维护,易复用,易扩展) 不如面向对象 具有封装,继承, ...
- linux最常用命令记录(一)
一.vim个人最常用设置: vim .vimrc 然后添加以下内容 set nu set tabstop=4 set encoding=utf-8 二.查看磁盘空间相关命令 1.df -h 查看硬 ...
- 为什么你学习了scrum之后还不会实施敏捷? (敏捷学习之旅一)
标题党, 其实这个主题改为"如何能快速的学习与实施敏捷"更贴切. 我在一家大型的外资金融企业,公司最近在大面积的实施敏捷转型,我的团队首先被选为试点团队,并实施得很好,最近我也和不 ...
- vue-cli实现最简单的全选、全不选、反选功能。不容错过呦!!!!!话不多说直接上代码。。。。
<template> <div class="hello"> <input type="button" name="al ...
- go-admin基于Gin + Vue + Element UI的前后端分离权限管理系统
✨ 特性 遵循 RESTful API 设计规范 基于 GIN WEB API 框架,提供了丰富的中间件支持(用户认证.跨域.访问日志.追踪ID等) 基于Casbin的 RBAC 访问控制模型 JWT ...
- 结巴分词demo
#encoding=utf-8 from __future__ import unicode_literals import sys sys.path.append("../") ...
- vim不能使用小键盘
使用终端登录Linux后使用vim编辑文本,这时在默认设置下载插入模式使用小键盘会插入一些非数字的字符. 更改的方法: 在终端设置中选择终端类型为linux
- 安卓手机tcpdump的使用
一.常规操作步骤 1. 手机要有root权限 2. 下载tcpdump http://www.strazzere.com/android/tcpdump 3. adb push c:\wherever ...
- Array.isArray() 判断是不是数组
var arr = new Array(); if(Array.isArray()){ console.log('yes') } else { conssole.log('no') }