Coding Test/[Python] Programmers lv1

[Python] Programmers lv1 모의고사

winCow 2021. 5. 3. 13:19

1. 제출코드

def solution(answers):
    answer = []
    give_up_man1 = [1, 2, 3, 4, 5]
    give_up_man2 = [2, 1, 2, 3, 2, 4, 2, 5]
    give_up_man3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
    give_up_man1s_hope = 0
    give_up_man2s_hope = 0
    give_up_man3s_hope = 0
    for ans in range(len(answers)):
        if answers[ans] == give_up_man1[ans % 5]:
            give_up_man1s_hope += 1
        if answers[ans] == give_up_man2[ans % 8]:
            give_up_man2s_hope += 1
        if answers[ans] == give_up_man3[ans % 10]:
            give_up_man3s_hope += 1
    max_value = max(give_up_man1s_hope, give_up_man2s_hope, give_up_man3s_hope)
    if max_value == give_up_man1s_hope:
        answer.append(1)
    if max_value == give_up_man2s_hope:
        answer.append(2)
    if max_value == give_up_man3s_hope:
        answer.append(3)
    return answer

 

 

2. 반성

max_value를 선언하기 전까지 각 수포자들의 맞춘 개수를 구하는 데까지는 성공했으나, 그 중 가장 큰 수를 구하는 데서 애를 먹었다. 가장 큰 수만 구하는 것은 쉬우나, 동점자들을 어떻게 처리해야 할지 감이 오지 않아 한참을 헤매다가, 결국 다른 사람의 풀이를 참고해서 위와 같이 풀었다. 1패를 적립하였으니 잘 기억해 두었다가 추후에 재도전해야겠다.