华为OD机试-考勤信息

华为OD机试-考勤信息_第1张图片

代码实现

# coding: utf-8
import numpy


class Solution:
    def chuqinInfo(self, n, arrs):
        res = []
        for i in range(n):
            arr = arrs[i]
            count = 0
            for s in arr:
                if str(s) == 'absent':
                    count += 1
            if count > 1:
                res.append('False')
                continue
            for i in range(len(arr) - 1):
                a = arr[i]
                b = arr[i + 1]
                if a in ('late', 'leaveearly') and b in ('late', 'leaveearly'):
                    res.append('False')
                    break
            for i in range(len(arr)):
                tmp = arr[i:1 + 7]
                counts = 0
                for ss in tmp:
                    if str(ss) == 'absent' or str(ss) == 'late' or str(ss) == 'leaveearly':
                        counts += 1
                if counts > 3:
                    res.append('False')
            else:
                res.append('True')
        return res


if __name__ == '__main__':
    n = int(input("input n:"))
    arrs = [0 for _ in range(n)]
    for i in range(n):
        arr = numpy.array(input('input arr:').split(' '))
        arrs[i] = arr
    solution = Solution()
    print(solution.chuqinInfo(n, arrs))

你可能感兴趣的:(测试小兵,算法,华为od,华为机试,python)