PAT甲级1006. Sign In and Sign Out

来源:互联网 发布:数据恢复高级技术 编辑:程序博客网 时间:2024/05/16 15:19

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

题目要求:

每天,第一个登录电脑的人开门,最后一个退出电脑的人关门;已知每个人登录和退出电脑的时间,需要找出开门的人和关门的人;

输入包括记录的条数,以及每个人的ID、登录、退出时间;ID字符串不超过15个字符,时间输入格式为HH:MM:SS;

输出要求:输出开门的人和关门的人ID,ID之间使用空格隔开;

题目的输入保证每个人登录时间早于退出时间,并且没有任何两个人的登录退出时间是相同的;

解题思路

方法一:直接使用int strcmp(const char *str1, const char *str2)比较输入的登录时间与输出时间的字符串的大小,因为数字对应的ASCII码是由小至大,所以可以用字符比较的方式,下面的代码即为方法一

#include "stdio.h"#include "stdlib.h"#include "string.h"#include "stdbool.h"typedef struct user {    char name[20];    char inTime[20];    char outTime[20];}user;int main() {    user user[100];    int num;    int unLockedIndex;    int lockedIndex;    char inTimeTmp[20];    strcpy(inTimeTmp,"23:59:59");    char outTimeTmp[20];    strcpy(outTimeTmp, "00:00:00");    unLockedIndex = 0;    lockedIndex = 0;    scanf("%d",&num);    for (int i = 0; i < num; i++)    {        scanf("%s",&user[i].name);        scanf("%s", &user[i].inTime);        //大于零表示第二个字符串小于第一个        if (strcmp(inTimeTmp, user[i].inTime)>0)        {            strcpy(inTimeTmp, user[i].inTime);            unLockedIndex = i;        }        scanf("%s", &user[i].outTime);        //表示第二个字符串大于第一个        if (strcmp(outTimeTmp, user[i].outTime)<0)            {                strcpy(outTimeTmp, user[i].outTime);                lockedIndex = i;            }    }    printf("%s %s",user[unLockedIndex].name,user[lockedIndex].name);    system("pause");    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 公租房人口少了怎么办 公租房太远了怎么办 商品房没有门厅业主该怎么办 公帐付款备注错了怎么办 我是农村户口在外省交社保怎么办 北京租房遇到黑中介怎么办 上海租房子不让带孩子怎么办 租的房子没窗户怎么办 北京安河桥安河家园租房被骗怎么办 领完失业金后怎么办 北京公租房太小怎么办 申请公租房太小怎么办 房东电费收贵了怎么办 申请公租房工资超了怎么办 重庆公租房工资超了怎么办 公租房申请父母房子贷款怎么办 公产房父母去世办公证怎么办 动迁过程中承租人去世了怎么办 公租房的房间带阳台怎么办 公租房合同到期没有社保怎么办 租房合同没有到期违约了怎么办 租房户到期不搬怎么办 公租房摇号摇到了又怎么办 公租房被清退会怎么办 公租房摇不到号怎么办 公租房到期不搬怎么办 租房到期租客不搬怎么办 房产证面积与实际不符怎么办 社保晚交了1天怎么办 个人社保忘交了怎么办 个人社保晚交了怎么办 医保晚交了几天怎么办 辞职后转为灵活就业养老怎么办 公司名称变更提取不了公积金怎么办 五险合一软件已经减员怎么办 法人社保不在投标单位怎么办 换工作单位后社保怎么办 在北京孩子没有一老一小怎么办 深户小孩怎么办社保卡 社保卡没办下来去医院住院怎么办 老年社保卡丢了怎么办