【PAT Advanced Level】1006. Sign In and Sign Out (25)
关键在于清空字符数组和使用scanf进行输入
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iostream>
using namespace std; int main()
{ int num;
while (scanf("%d", &num) != EOF)
{ char earlest[20];
char lastest[20];
char thisone[20];
int h1, h2, m1, m2, s1, s2;
scanf("%s%d%*c%d%*c%d %d%*c%d%*c%d", &thisone, &h1, &m1, &s1, &h2, &m2, &s2);
int ear = 3600 * h1 + 60 * m1 + s1;
int lat = 3600 * h2 + 60 * m2 + s2;
memcpy(earlest, thisone, sizeof(thisone)/sizeof(char));
memcpy(lastest, thisone, sizeof(thisone)/sizeof(char));
num--;
while (num--)
{
memset(thisone, 0, sizeof(thisone)/sizeof(char));
scanf("%s%d%*c%d%*c%d %d%*c%d%*c%d", &thisone, &h1, &m1, &s1, &h2, &m2, &s2);
int tmp1 = 3600 * h1 + 60 * m1 + s1;
int tmp2 = 3600 * h2 + 60 * m2 + s2;
if(ear > tmp1)
{
//earlest[0] = '\0';
memset(earlest, 0, sizeof(earlest)/sizeof(char));
memcpy(earlest, thisone, sizeof(thisone)/sizeof(char));
ear = tmp1;
}
if(lat < tmp2)
{
//lastest[0] = '\0'; //清空字符数组,也可以用下面一种方法,更为保险
memset(lastest, 0, sizeof(lastest)/sizeof(char));
memcpy(lastest, thisone, sizeof(thisone)/sizeof(char));
lat = tmp2;
}
} printf("%s %s\n", earlest, lastest);
}
}
【PAT Advanced Level】1006. Sign In and Sign Out (25)的更多相关文章
- 【PAT Advanced Level】1008. Elevator (20)
没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...
- 【PAT Advanced Level】1004. Counting Leaves (30)
利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...
- 【PAT Advanced Level】1014. Waiting in Line (30)
简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...
- 【PAT Advanced Level】1015. Reversible Primes (20)
转换进制&&逆序可以在一起进行,有一点技巧,不要用十进制数来表示低进制,容易溢出. #include <iostream> #include <vector> ...
- 【PAT Advanced Level】1011. World Cup Betting (20)
简单模拟题,遍历一遍即可.考察输入输出. #include <iostream> #include <string> #include <stdio.h> #inc ...
- 【PAT Advanced Level】1013. Battle Over Cities (25)
这题给定了一个图,我用DFS的思想,来求出在图中去掉某个点后还剩几个相互独立的区域(连通子图). 在DFS中,每遇到一个未访问的点,则对他进行深搜,把它能访问到的所有点标记为已访问.一共进行了多少次这 ...
- 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 (Advanced Level) Practice 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, ...
- PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)
简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...
随机推荐
- HTML5学习(十)---Web Workers
参考教程:http://www.w3school.com.cn/html5/html_5_webworkers.asp web worker 是运行在后台的 JavaScript,不会影响页面的性能. ...
- poj1823,3667
又来练线段树了…… poj1823题意很简单(明显的数据结构题),区间修改和统计最长连续空区间: 有了poj3468的基础,区间修改不是什么问题了,重点是求最长连续空区间:(弱弱的我纠结了好久) 在每 ...
- Java web 项目 tomcat部署方式.
本地做Java Web项目的时候常常会用到tomcat部署测试的问题, 这里介绍项目的部署方法: 1,配置文件的形式: 例如: 你的项目目录为:f:\workspaces\MyProject,此时使用 ...
- 架构版本与 NuGet 的版本不兼容 解决方案
VS的NuGet管理在大大提高了开发效率,一直都在使用但今天在遇到了一个问题,引用一个所需要的NuGet包VS缺提示如下错误
- (2015年郑州轻工业学院ACM校赛题) J 堆
判断是否是一个堆,把树构造好遍历一遍就OK了 #include<stdio.h> #include<iostream> #include<stack> #inclu ...
- BlockingQueue汇总
前言: 在新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便 ...
- linux time命令参数--执行命令并计时
[命令]time — 执行命令并计时 [格式]time [-p] command [arguments...] [说明] 执行命令行"command [arguments...]" ...
- Zabbix探索:工作时间的设置
默认情况下,Zabbix的工作时间是启用的. 启用后,图形的北京在工作时间内就是白底的,否则就是灰底的. 今天纠结了半天,因为无论如何都是灰底的. 后来连接到服务器上一看,靠,忘记同步时间了,所以刚好 ...
- NOIP2006 能量项链
洛谷1063 能量项链 本题地址:http://www.luogu.org/problem/show?pid=1063 题目描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N ...
- uva 11916 Emoogle Grid
题意:用K种颜色给一个N*M的格子涂色.其中有B个格子是不能涂色的.涂色时满足同一列上下紧邻的两个格子的颜色不同.所有的涂色方案模100000007后为R.现在给出M.K.B.R,求一个最小的N,满足 ...