关键在于清空字符数组和使用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. 转载:C++ vector 类学习笔记

    声明:本文转载自http://blog.csdn.net/whz_zb/article/details/6827999 vector简介 vector是STL中最常见的容器,它是一种顺序容器,支持随机 ...

  2. write_chip,read_chip

    int write_chip(UINT32 addr, UINT32 data) { if(0 == fpgaRWMode) /* localbus mode */ { UINT16 datah, d ...

  3. 浅谈HTTP中Get、Post、Put与Delete的区别

    Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...

  4. javascript两行代码按指定格式输出日期时间

    javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...

  5. apache开源项目--TIKA

    Tika是一个内容抽取的工具集合(a toolkit for text extracting).它集成了POI, Pdfbox 并且为文本抽取工作提供了一个统一的界面.其次,Tika也提供了便利的扩展 ...

  6. 在文件中读取、存储Json格式的字符串

    public class Weather { static readonly string FilePath = System.Environment.CurrentDirectory + @&quo ...

  7. Doing Homework(HDU 1074状压dp)

    题意:给你n个要做的作业,它们的名字.期限.可完成所需天数(必须连续)在规定期限不能完成要扣分(每天一分)求做作业顺序使扣分最少. 分析:作业数量较少,用状态压缩,做到第i种作业花费的天数dp[i]. ...

  8. tomcat Connector 连接器

    连接器的核心功能,本文去除非核心功能,留下整个程序的框架,便于理解. 1.接受连接请求 2.创建request,和response. 3.调用容器对应的Invoke方法, 首先看类的依赖结构. 1.C ...

  9. uva11732 strcmp() Anyone?

    题意:给出多个字符串,两两配对,求总配对次数. 思路:如果两个字符串一样,ans=strlen(字符串)*2+2,如果不同,ans=公共前缀长度*2+1:用左儿子右兄弟建字典树.插入一个字符计算一次. ...

  10. Magento 多语言

    一: 1>进入后台选择如下: 2> 显示页面如下: 输入后台登陆的用户名和密码. 3>然后去Magento官网搜索一下 Magento Official Chinese Transl ...