笔试时间:2023年8月30日 秋招 第一题 题目:智慧打卡系统 某家高科技公司为方便员工省去每日上下班的打卡操作,计划推广使用智慧打卡系统。其运行的原理是系统会记录员工当日进出门禁的时间(员工在上班期间可能会多次进出门禁,格式为24小时制,小时:分钟,“HH:MM”)。现在请编写一个算法,计算员工当日的工作时长(单位:分钟),具体要求如下: 1、单次离岗15min以内,不从工作时长中扣除。 2、12:00至14:00为午休时间,不算工作时长。 3、18:00至19:30为晚饭时间,不算工作明长。 解答要求 时间限制:C/C++1000ms其他语言:2000ms内存限制:C/C++256MB其他语言:512MB 输入描述 第一行:员工当天进门禁的次数n。 第二行:员工当天进门禁的所有时间,以空格分隔。 第三行:员工当天出门禁的次数m。 第四行:员工当天出门禁的所有时间,以空格分隔。 注:0<n,m<100,不存在相同的出入门禁时间,也不存在连续的出门禁或入门禁的情况。 输出描述 当日的工作时长。 样例输入 示例一: 5 07:50 08:50 12:30 13:40 19:50 5 08:45 12:20 13:20 18:30 20:30 示例二: 4 08:30 12:30 14:00 18:20 4 12:00 13:00 16:50 19:00 样例输出 530 解释:员工的工作时段为07:50-12:00,14:00~18:00,19:50~20:30,工作时长为530分钟 示例二: 380 解释员工的工作时段为08:30~12:00,14:00~16:50,工作时长为380分钟 参考题解 模拟 Python: from datetime import datetimeformat = "%H:%M"n = int(input())intime = [c for c in input().split()]for i in range(n): intime[i] = datetime.strptime(intime[i], format)m = int(input())outtime = [c for c in input().split()]for i in range(n): outtime[i] = datetime.strptime(outtime[i], format)wuxiu_s, wuxiu_e = datetime.strptime("12:00", format), datetime.strptime("14:00", format)wanfan_s, wanfan_e = datetime.strptime("18:00", format), datetime.strptime("19:30", format)res = 0tmp1 = []tmp2 = []tmp = []#先处理小于15分钟的情况for i in range(n-1): if ((intime[i+1] - outtime[i]).total_seconds() / 60) <= 15: tmp1.append(i+1) tmp2.append(i)n1, n2 = [], []for i in range(n): if i not in tmp1: n1.append(intime[i]) if i not in tmp2: n2.append(outtime[i])intime, outtime = n1, n2for i in range(len(intime)): # 午休前进来 午休后出去 if intime[i] < wuxiu_s and (wuxiu_s < outtime[i] < wuxiu_e or outtime[i] > wuxiu_e) : res += (wuxiu_s - intime[i]).total_seconds()/60 # 午休进来 午休出去 elif wuxiu_s < intime[i] < wuxiu_e and wuxiu_s < outtime[i] < wuxiu_e : continue #午休进来 午休后 晚饭前出去 elif wuxiu_s < intime[i] < wuxiu_e and wuxiu_e < outtime[i] < wanfan_s : res += (outtime[i] - wuxiu_e).total_seconds()/60 # 午休进来 晚饭的时候出去 elif wuxiu_s < intime[i] < wuxiu_e and wanfan_s < outtime[i] < wanfan_e : res += (wanfan_s - wuxiu_e).total_seconds()/60 #午休进来 晚饭后出去 elif wuxiu_s < intime[i] < wuxiu_e and wanfan_e < outtime[i]: res += (wanfan_s - wuxiu_e + outtime[i