practivceAlgorithm/swexpertacademy

[SWEA][Python] 1240 단순2진암호코드

findTheValue 2021. 9. 29. 17:41

암호를 찾으면 7자리씩 decoding하고 배열에 저장해 유효성 판단하고 값을 반환합니다.

따로 알고리즘이 필요한 문제는 아닙니다.

 

for test in range(1, int(input()) + 1):
    N, M = map(int, input().split())
    nums = {'0001101': 0, '0011001': 1, '0010011': 2, '0111101': 3, '0100011': 4, '0110001': 5, '0101111': 6, '0111011': 7, '0110111': 8, '0001011': 9}
    bits = []
    for _ in range(N):
        a = input()
        idx = 0
        if bits: continue
        while idx < M - 7:
            idx += 1
            if a[idx:idx+7] in nums and not int(a[idx + 7]):
                bits.append(nums[a[idx:idx+7]])
                idx += 6
    answer = sum(bits) if not (sum(bits) + 2 * sum(bits[0:7:2])) % 10 else 0
    print(f'#{test} {answer}')