欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PAT 甲级真题 1006 Sign In and Sign Out (25分) python实现

程序员文章站 2022-08-06 19:17:10
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 th...

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

具体思路

就找出最早到和最晚出去的,我认为啊这种输入复杂的,可以考虑python(我只学了python和c,python还自学)

具体代码

def mian():#主函数
    zhong=(int)(input(''))#输入个数
    zhu=[]#储存时间
    ming=[]#储存名字
    for i in range(zhong):
        x=input('').split( )#先分解为三部分
        ming.append(x[0])#名字加入列表
        l=x[1]
        l=l.split(":")#根据:分裂加入另一个列表
        zhu.append(int(l[0]))
        zhu.append(int(l[1]))
        zhu.append(int(l[2]))
        z=x[2]
        z=z.split(":")
        zhu.append(int(z[0]))
        zhu.append(int(z[1]))
        zhu.append(int(z[2]))
    chang=zhong*6#时间列表的长度
    biaoji=0#记录最小值的标号
    biaoji2=0#记录最大值的标号
    for i in range(0,chang,6):#三重判断判断谁最小
        if(zhu[biaoji]>zhu[i]):
            biaoji=i
        elif(zhu[biaoji]==zhu[i]):
            if(zhu[biaoji+1]>zhu[i+1]):
                biaoji=i
            elif(zhu[biaoji+1]==zhu[i+1]):
                if(zhu[biaoji+2]>zhu[i+2]):
                    biaoji=i
    for i in range(3,chang,6):#三重判断谁最大
        if(zhu[biaoji2]<zhu[i]):
            biaoji2=i
        elif(zhu[biaoji2]==zhu[i]):
            if(zhu[biaoji2+1]<zhu[i+1]):
                biaoji2=i
            elif(zhu[biaoji2+1]==zhu[i+1]):
                if(zhu[biaoji2+2]<zhu[i+2]):
                    biaoji2=i
     
    biaoji=int(biaoji/6)#一个名字的时间占6个,故除以6
    biaoji2=int(biaoji2/6)
    print("{} {}".format(ming[biaoji],ming[biaoji2]))#输出
mian()#调用
        
        

具体结果

PAT 甲级真题 1006 Sign In and Sign Out (25分) python实现
代码有错误,请指出,一起进步,谢谢!

本文地址:https://blog.csdn.net/xiejianhao1/article/details/107564155