• PAT1006


    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:

    测试用例由一个正整数M开始,表示记录的数量,接下来有M行,每一行的格式如下

    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.

    给出的时间格式是HH:MM: SS,ID不会超过15个字符

    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.

    对于每个测试用例,输出一行,解锁和锁的人的ID

    The two ID numbers must be separated by one space.

    两个ID必须用一个空格分开

    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

    自己的代码太low了,我去,我干啥要一个个读取,干嘛要一个个去比较,我是不是蠢货啊。

    这里推荐直接字符串比较就可以了。我真的是,写了一大堆才发现自己有多蠢。。。这种错误不能犯第二次,下一次一定要记住。下面是网上的代码,真的很简练很爽。

    #include<stdio.h>  
        #include<string.h>  
        int main(){  
            char lkman[20],unlkman[20];  
            char id[20],in[20],out[20];  
            char fst[20]={"24:00:00"},last[20]={"00:00:00"};  
            int i,j,n;  
            scanf("%d",&n);  
            for(i=0;i<n;i++){  
                scanf("%s %s %s",id,in,out);  
                if(strcmp(in,fst)<0){  
                    strcpy(fst,in);  
                    strcpy(unlkman,id);  
                }  
                if(strcmp(out,last)>0){  
                    strcpy(last,out);  
                    strcpy(lkman,id);  
                }  
            }  
            printf("%s %s
    ",unlkman,lkman);  
            return 0;  
        }

    代码转载自:http://blog.csdn.net/sup_heaven/article/details/8451669

  • 相关阅读:
    javascript Math.random()随机数函数
    asp.net 前台获取后台c#代码信息
    关于C#网站一般处理程序(ashx)中session的问题
    怎样才能在一般处理文件中创建新的Session和访问已经存在的Session?
    使用SqlParameter向数据库中插入数据
    C#串口编程学习简单实例
    认识nodejs
    01.Javascript中的接口Interface [转载]
    动态添加脚本,并触发回调函数 初步实现按需加载
    JS正则表达式 收藏
  • 原文地址:https://www.cnblogs.com/linkstar/p/5677301.html
Copyright © 2020-2023  润新知