JehooJeon / algorithm_review

알고리즘 수업 코드리뷰
0 stars 0 forks source link

1240. 단순 2진 암호코드 #11

Open JehooJeon opened 3 months ago

JehooJeon commented 3 months ago

https://swexpertacademy.com/main/talk/solvingClub/problemView.do?solveclubId=AZC_w6Z6yygDFAQW&contestProbId=AV15FZuqAL4CFAYD&probBoxId=AZDJPc6a-dsDFAVs&type=PROBLEM&problemBoxTitle=1d_practice&problemBoxCnt=4

JehooJeon commented 3 months ago
# 1240. [S/W 문제해결 응용] 1일차 - 단순 2진 암호코드

import sys
sys.stdin = open("input.txt", 'r')

for tc in range(1, int(input())+1):
    N, M = map(int, input().split())
    code_output = {'0001101': 0, '0011001': 1, '0010011': 2, '0111101': 3, '0100011': 4,
                   '0110001': 5, '0101111': 6, '0111011': 7, '0110111': 8, '0001011': 9}
    input_list = [input() for _ in range(N)]

    code = ''
    for input in input_list:
        if '1' in input:
            code = input
            break

    for i in range(len(code)-1, -1, -1):
        if code[i] == '1':
            real_code = code[i-55:i+1]
            break

    results = []
    for i in range(8):
        results.append(code_output[real_code[i*7:i*7+7]])

    code_sum = 0
    for i in range(8):
        if i % 2 == 0:
            code_sum += results[i] * 3
        else:
            code_sum += results[i]

    if code_sum % 10 == 0:
        answer = sum(results)
    else:
        answer = 0

    print(f"#{tc} {answer}")