zoukankan      html  css  js  c++  java
  • PAT(A) 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
    
    #include <cstdio>
    #include <cstring>
    
    //划重点(1):结构体内找最大最小 great()
    struct pNode{
       char id[20]; //string id; //要报错 int h, m, s; }tmp, ans1, ans2; //ans1存放最早签到时间 ans2存放最晚签离时间 bool great(pNode node1, pNode node2){ //node1的时间 > node2的时间 则返回true
       if(node1.h != node2.h) return node1.h>node2.h; if(node1.m != node2.m) return node1.m>node2.m; return node1.s>node2.s; } int main() { int M=10; //划重点(2):C语音带格式的文件输入 //FILE *fp; //fp=fopen("test.txt", "r"); //fscanf(fp, "%d", &M); scanf("%d", &M); //划重点(3):找最小,初始设为最大 ans1.h=24, ans1.m=60, ans1.s=60; //初始签到时间设为最大 ans2.h=0, ans2.m=0, ans2.s=0; //初始签离时间设为最小 for(int i=0; i<M; i++){ //先读入ID和签到时间 scanf("%s%d:%d:%d", &tmp.id, &tmp.h, &tmp.m, &tmp.s); if(great(tmp, ans1) == false) ans1=tmp; //取更小的签到时间(整个结构体赋值) //再读入签离时间 scanf("%d:%d:%d", &tmp.h, &tmp.m, &tmp.s); if(great(tmp, ans2) == true) ans2=tmp; //取更大的签离时间 } printf("%s %s", ans1.id, ans2.id); return 0; }
  • 相关阅读:
    mac上的键盘生活——打字训练

    011-黑盒测试的测试用例常见设计方法都有哪些?请分别以具体的例子来说明这些方法在测试用例设计工作中的应用
    010-如何测试一个 纸杯?
    009-条软件缺陷(或者叫 Bug)记录都包含了哪些内容?如何提交高质量的软件缺陷(Bug)记录?
    008-黑盒测试和白盒测试的优缺点
    007-测试人员在软件开发过程中的任务是什么?
    006- 软件产品质量特性是什么?
    005-目前主要的测试用例设计方法是什么?
    007-软件测试分类
  • 原文地址:https://www.cnblogs.com/claremore/p/6548117.html
Copyright © 2011-2022 走看看