CS/Algorithm 문제

[Programmers] 모의고사

심심231 2021. 10. 14. 11:45

[Programmers] 모의고사

 

🎈문제

https://programmers.co.kr/learn/courses/30/lessons/42840

💬설명

  • 데이터 크기도 크지 않고 학생 수도 3명으로 정해져 있었기 때문에 약간의 하드코딩을 가미해서(?) 완탐으로 풀었다.

👩‍💻코드

def solution(answers):
    answer = []
    answer_n = len(answers)
    
    correct1 = 0
    select1 = [1, 2, 3, 4, 5]
    
    correct2 = 0
    select2 = [2, 1, 2, 3, 2, 4, 2, 5]
    
    correct3 = 0
    select3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
    
    for i in range(answer_n):
        if select1[i % 5] == answers[i]:
            correct1 += 1
        if select2[i % 8] == answers[i]:
            correct2 += 1
        if select3[i % 10] == answers[i]:
            correct3 += 1

    arr = [correct1, correct2, correct3]
    correct_max = max(arr)
    for i in range(3):
        if arr[i] == correct_max:
            answer.append(i + 1)

    return answer
728x90
반응형