题目
公司用一个字符串来表示员工的出勤信息:
- absent: 缺勤;
- late: 迟到;
- leaveearly: 早退;
- present: 正常上班
现在根据员工出勤信息,判断本次能否获得出勤奖,能获得出勤奖的条件如下: - 缺勤不超过一次;
- 没有连续的迟到/早退;
- 任意连续7次考勤,缺勤/迟到/早退不超过3次;
输入描述:
考勤数据字符串的记录条数n 【1,…】;
n行的考勤字符串;
输出描述:
能得到考勤奖,输出“true”;
否则输出“false”
示例1
输入:
2
present
present present
输出:
true
true
示例2
输入:
2
present
present absent present present leaveearly present absent
输出:
true
false
解题代码
def judge(alist):# 统计 absent 次数ab_count = 0for i in alist:if i == "absent":ab_count += 1if ab_count > 1:return False# 是否连续迟到/早退flag = Falsetgt_label = ["late", "leaveearly"]for idx in range(len(alist) - 1):if alist[idx] in tgt_label and alist[idx+1] in tgt_label:flag = Trueif flag:return Falseif len(alist) < 7:return Trueelse:# 统计 缺勤、迟到、早退的总次数total_count = 0total_list = ["absent", "late", "leaveearly"]for i in alist:if i in total_list:total_count += 1return total_count <= 3n = int(input().strip())
records = []
for i in range(n):records.append(input().strip().split())result = []
for idx in range(n):result.append(judge(records[idx]))for v in result:if v:print("true")else:print("false")