每天的记录在第一行给出记录的条目数M (M > 0 ),下面是M行,每行的格式为 证件号码 签到时间 签离时间 其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。 注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,且没有多人同时签到或者签离的情况。
3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40
SC3021234 CS301133
时间的比较和数字的比较是等效的,所以可以直接取最大最小,即最早最晚。再获取对应的索引去找人即可。
def main(): n = int(input()) pid,stime,etime = [],[],[] for i in range(n): ntime = input() xxx = ntime.split(' ') pid.append(xxx[0]) stime.append(xxx[1]) etime.append(xxx[2]) sp = pid[stime.index(min(stime))] ep = pid[etime.index(max(etime))] print(sp, ep) if __name__ == '__main__': main()
while True: try: n=int(input().strip()) inp=[] def data(i): sum1=0 sum1+=int(i.split(':')[0])*3600+int(i.split(':')[1])*60+int(i.split(':')[2])*1 return sum1 for i in range(n): inp.append(list(input().strip().split(' '))) dict1={} for i in inp: first=data(i[1]) last=data(i[2]) dict1[i[0]]=[first,last] dict1_1=sorted(dict1.items(),key=lambda x:x[1][0]) dict2_1=sorted(dict1.items(),key=lambda x:x[1][1],reverse=True) re1=dict1_1[0][0] re2=dict2_1[0][0] print(re1+' '+re2) except: break
try: while True: num = int(input()) idNum = [] signIn = [] signOut = [] for i in range(num): temp = input().split() idNum.append(temp[0]) signIn.append(temp[1]) signOut.append(temp[2]) a = idNum[signIn.index(min(signIn))] #找出签到的最小值 b = idNum[signOut.index(max(signOut))] #找出签退的最大值 print("%s %s" % (a,b)) except Exception: pass
def main(): n = int(input()) earliest_stu = '' latest_stu = '' earliest_come = 240000 latest_leave = -1 for i in range(n): temp = input().split() temp[1] = int(temp[1].replace(':', '')) temp[2] = int(temp[2].replace(':', '')) if temp[1] < earliest_come: earliest_come = temp[1] earliest_stu = temp[0] if temp[2] > latest_leave: latest_leave = temp[2] latest_stu = temp[0] print('%s %s'%(earliest_stu, latest_stu)) while True: try: main() except: break