关键在于清空字符数组和使用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)的更多相关文章

  1. 【PAT Advanced Level】1008. Elevator (20)

    没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...

  2. 【PAT Advanced Level】1004. Counting Leaves (30)

    利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...

  3. 【PAT Advanced Level】1014. Waiting in Line (30)

    简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOME ...

  4. 【PAT Advanced Level】1015. Reversible Primes (20)

    转换进制&&逆序可以在一起进行,有一点技巧,不要用十进制数来表示低进制,容易溢出. #include <iostream> #include <vector> ...

  5. 【PAT Advanced Level】1011. World Cup Betting (20)

    简单模拟题,遍历一遍即可.考察输入输出. #include <iostream> #include <string> #include <stdio.h> #inc ...

  6. 【PAT Advanced Level】1013. Battle Over Cities (25)

    这题给定了一个图,我用DFS的思想,来求出在图中去掉某个点后还剩几个相互独立的区域(连通子图). 在DFS中,每遇到一个未访问的点,则对他进行深搜,把它能访问到的所有点标记为已访问.一共进行了多少次这 ...

  7. 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 ...

  8. 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, ...

  9. PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)

    简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...

随机推荐

  1. poj 2109 Power of Cryptography (double 精度)

    题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...

  2. 5个难以置信的VS 2015预览版新特性

    Visual Studio 2015 Preview包含了很多强大的新特性,无论你是从事WEB应用程序开发,还是桌面应用程序开发,甚至是移动应用开发,VS 2015都将大大提高你的开发效率.有几个特性 ...

  3. UVA 1515 Pool construction 水塘(最大流,经典)

    题意: 给一个h*w的矩阵,每个格子中是'#'和'.'两个符号之一,分别代表草和洞.现在要将洞给围起来(将草和洞分离),每条边需花费b元(即将一个洞包起来需要4边,将2个连续的洞包起来需要6边,省了2 ...

  4. Java传参那些事!

    刚刚学习java传参的时候很纠结,也非常的不理解!课本上的“按值传递”和“按址传递”搞的自己是一头雾水,后来写的项目多了,自然就明白了! 现在写传参几乎就是条件反射一般——“秒成”,分享当初自己为此写 ...

  5. tomcat+oracle连接池

    tomcat 5.5.23 oracle 10g 全局配置 一.tomcat目录\common\lib下添加包ojdbc14.jar. 二.tomcat目录\conf\server.xml的<G ...

  6. ubuntu终端提示符@name修改

    需要修改两个文件: 1.在终端输入 vim  /etc/hosts 将当前的name改为ubuntu: 2.在终端输入 vim /etc/hostsname 将当前的name改为ubuntu: 3.重 ...

  7. python 网络编程(五)---DNS域名系统

    1.域名系统定义 DNS计算机域名系统由域名服务器和域名解析器组成.通常输入的是网址就是一个域名. 2.域名查询 查询方式包括: 1)正向查询:由域名查找对应的IP(如:www.baidu.com—& ...

  8. Linux 下文件名乱码(无效的编码)的解决办法

    文件是在WIndows 下创建的,Windows 的文件名中文编码默认为GBK,而Linux中默认文件名编码为UTF8,由于编码 不一致所以导致了文件名乱码的问题,解决这个问题需要对文件名进行转码. ...

  9. 检索表中所有列的名称、DB中的用户表

    一.检索某个表中所有列的名称 SELECT name FROM syscolumns WHERE ID = OBJECT_ID('Departments') syscolumns (sys.sysco ...

  10. IOS上的字符编码

    IOS字符编码 字符编码经常能听到的有Unicode.UTF-8.GBK.GB2312.GB18030.BIG5等.这些编码方式都有什么区别呢? 其实这些编码,大体分两类:全球统一编码和各过个语种的独 ...