自学内容网 自学内容网

OD B卷【考勤信息】

题目

公司用一个字符串来表示员工的出勤信息:

  • 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 = 0
    for i in alist:
        if i == "absent":
            ab_count += 1
    if ab_count > 1:
        return False

    # 是否连续迟到/早退
    flag = False
    tgt_label = ["late", "leaveearly"]
    for idx in range(len(alist) - 1):
        if alist[idx] in tgt_label and alist[idx+1] in tgt_label:
            flag = True
    if flag:
        return False

    if len(alist) < 7:
        return True
    else:
        # 统计 缺勤、迟到、早退的总次数
        total_count = 0
        total_list = ["absent", "late", "leaveearly"]
        for i in alist:
            if i in total_list:
                total_count += 1
        return total_count <= 3


n = 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")

原文地址:https://blog.csdn.net/weixin_45228198/article/details/144317145

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!