알고리즘/프로그래머스

[파이썬][프로그래머스] 완전탐색 모의고사

SBOX Learning by doing 2022. 11. 25. 22:00
반응형

def solution(answers):
    
    one_answer = [1,2,3,4,5]
    two_answer = [2,1,2,3,2,4,2,5]
    three_answer = [3,3,1,1,2,2,4,4,5,5]
    one_coin = 0
    two_coin = 0
    three_coin = 0
    
    # one
    one_count = 0
    for answer in answers:
        if answer == one_answer[one_count % len(one_answer)]:
            one_coin += 1
        one_count += 1
    
    # two
    two_count = 0
    for answer in answers:
        if answer == two_answer[two_count % len(two_answer)]:
            two_coin += 1
        two_count += 1
    
    # three
    three_count = 0
    for answer in answers:
        if answer == three_answer[three_count % len(three_answer)]:
            three_coin += 1
        three_count += 1
    max_coin = max(one_coin, two_coin, three_coin)
    
    # max 인값을 찾고 같은 값 리턴
    answer = []
    if max_coin == one_coin:
        answer.append(1)
    if max_coin == two_coin:
        answer.append(2)
    if max_coin == three_coin:
        answer.append(3)
    return answer

반응형