关键在于清空字符数组和使用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. awesome awesomeness

    Awesome Awesomeness A curated list of amazingly awesome awesomeness.Also available on: Awesome-Aweso ...

  2. jsoi2015 R2——滚粗记

    考完感觉各种绝望溢出胸口,作为百度空间的最后一篇文章了吧 day 0 第二轮在南师附中……不能到外地玩了…… 其实在试机的时候就感觉不大对头,明明说好18:15试机结果拖到18:30…… 还有今年竟然 ...

  3. SSMS错误代码大全

    0 操作成功完成. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒绝访问. 6 句柄无效. 7 存储控制块被损坏. 8 存储空间不足,无法处理此 ...

  4. android 三目运算符 运用错误

    /************************************************************************** * android 三目运算符 运用错误 * 说 ...

  5. 网站资料收集 主要查看js的学习部分

    1.Asp.Net MVC3.0基本的简单的可能都会用,更深入的使用还需加深研究,之后希望对MVC4.0和5.0进行对比学习,暂时看到@葡萄城控件技术团队博客的MVC5系列正在继续http://www ...

  6. CentOS 7 安装 tomcat7.0

    安装tomcat: [root@admin local]# cd /usr/local[root@admin local]# tar -zxv -f apache-tomcat-7.0.29.tar. ...

  7. 【转】FragmentTest学习笔记1

    原文网址:http://blog.csdn.net/hishentan/article/details/20734489 源码部分: BookContent.java package com.exam ...

  8. POJ 3126 Prime Path BFS搜索

    题意:就是找最短的四位数素数路径 分析:然后BFS随便搜一下,复杂度最多是所有的四位素数的个数 #include<cstdio> #include<algorithm> #in ...

  9. java.lang.ExceptionInInitializerError的原因(转)

    这个错误是说变量初始化出现问题,通常出现在静态变量尤其是单例模式.这种问题往往是初始化顺序不对造成的,下面举个简单的例子. import java.util.HashMap; import java. ...

  10. js 数组常用方法说明

    //push 向数组最后添加一项 var arr = ['one', 'two', 'three']; arr.push("four"); console.log(arr);//[ ...