개발자 톡

연습문제 톡 [21년 재직자 대회 예선] 전광판

재직자 예전_전광판

등록일
2021-12-20 16:41:19
조회수
701
작성자
prettyrain85


import sys

test_case = int(input()) # 첫줄 입력받음

#####  전구의 위치를 리스트화
num_none = [0, 0, 0, 0, 0, 0, 0]
num_0 = [1, 1, 1, 0, 1, 1, 1]
num_1 = [0, 0, 1, 0, 0, 1, 0]
num_2 = [1, 0, 1, 1, 1, 0, 1]
num_3 = [1, 0, 1, 1, 0, 1, 1]
num_4 = [0, 1, 1, 1, 0, 1, 0]
num_5 = [1, 1, 0, 1, 0, 1, 1]
num_6 = [1, 1, 0, 1, 1, 1, 1]
num_7 = [1, 1, 1, 0, 0, 1, 0]
num_8 = [1, 1, 1, 1, 1, 1, 1]
num_9 = [1, 1, 1, 1, 0, 1, 1]
###################################


def num_change_first(first): # 첫번째 비교숫자를 전구 순서로 변경
    # print("멍미? first 함수가 실행되었습니다.")
    # print(first, type(first))

    if len(first) == 1:
        first = "a"+"a"+"a"+"a"+first
    elif len(first) == 2:
        first = "a"+"a"+"a"+first
    elif len(first) == 3:
        first = "a"+"a"+first
    elif len(first) == 4:
        first = "a"+first
    elif len(first) == 5:
        first = first
    # print(first, type(first)) # 5자리로 변환은 성공적입니다.
    
    first_list = []

    for j in first:
        # print(j, type(j))
        if j == "a":
            first_list.append(num_none)
        elif j == "0":
            first_list.append(num_0)
        elif j == "1":
            first_list.append(num_1)
        elif j == "2":
            first_list.append(num_2)
        elif j == "3":
            first_list.append(num_3)
        elif j == "4":
            first_list.append(num_4)
        elif j == "5":
            first_list.append(num_5)
        elif j == "6":
            first_list.append(num_6)
        elif j == "7":
            first_list.append(num_7)
        elif j == "8":
            first_list.append(num_8)
        elif j == "9":
            first_list.append(num_9)

    # print(first_list, type(first_list))

    first_list = sum(first_list,[])
    # print(first_list, type(first))
    return first_list

def num_change_second(second):  # 두번째 비교숫자를 전구 순서로 변경
    # print("second 함수가 실행되었습니다.")
    # print(first, type(first))

    if len(second) == 1:
        second = "a"+"a"+"a"+"a"+second
    elif len(second) == 2:
        second = "a"+"a"+"a"+second
    elif len(second) == 3:
        second = "a"+"a"+second
    elif len(second) == 4:
        second = "a"+second
    elif len(second) == 5:
        second = second
    # print(second, type(second)) # 5자리로 변환은 성공적입니다.
    
    second_list = []

    for j in second:
        # print(j, type(j))
        if j == "a":
            second_list.append(num_none)
        elif j == "0":
            second_list.append(num_0)
        elif j == "1":
            second_list.append(num_1)
        elif j == "2":
            second_list.append(num_2)
        elif j == "3":
            second_list.append(num_3)
        elif j == "4":
            second_list.append(num_4)
        elif j == "5":
            second_list.append(num_5)
        elif j == "6":
            second_list.append(num_6)
        elif j == "7":
            second_list.append(num_7)
        elif j == "8":
            second_list.append(num_8)
        elif j == "9":
            second_list.append(num_9)

    # print(first_list, type(first_list))

    second_list = sum(second_list,[])
    # print(first_list, type(first))
    return second_list

def check_cnt(first, second): # 숫자끼리 비교하며 숫자가 서로 다르면 cnt를 올림
    cnt = 0
    for i in range(35):
        if first[i] == second[i]:
            cnt += 0
        elif first[i] != second[i]:
            cnt += 1
        # print(i, type(i)) # int 값으로 값 나옴
    return cnt

for i in range(test_case):
    # print(i)

    test = list(map(int, sys.stdin.readline().split())) # test = [1, 2]    test = [9881, 10724]
    # print(test, type(test))
    first = str(test[0])
    second = str(test[1])
    
    first = num_change_first(first)
    # print(first)
    # print(len(first)) # 리스트 길이는 35
    
    second = num_change_second(second)
    # print(second)
    # print(len(second)) # 리스트 길이는 35

    final_cnt = 0
    final_cnt = check_cnt(first, second)
    print(final_cnt)


위와같이 코딩하여 문제는 풀었습니다.

그런데 의문점은 다른분들고 이렇게 하셨는지 궁금합니다.


혹시 숏코딩 하신분 코드좀 알 수 있을까요?

#[21년_재직자_대회_예선]_전광판
#파이썬
#재직자_예선_전광판
#숏코딩

이 카테고리의 톡 더보기