[프로그래머스 코딩테스트]모의고사

최대 1 분 소요

[프로그래머스 코딩테스트 고득점 kit] 모의고사 (Python)

:pencil2:문제 링크

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

:pencil2:문제풀이

def solution(answers):
    
    supo1 = 0
    supo2 = 0
    supo3 = 0
    
    # 1번 수포자의 변수
    supo1_arr = [1,2,3,4,5]
    
    # 2번 수포자의 변수
    supo2_arr = [2,1,2,3,2,4,2,5]
    
    # 3번 수포자의 변수
    supo3_arr = [3,3,1,1,2,2,4,4,5,5]
    
    for i in range(len(answers)):
        # 1번 수포자의 채점
        if answers[i] == supo1_arr[i%5]:
            supo1 += 1
        
        # 2번 수포자의 채점
        if answers[i] == supo2_arr[i%8]:
            supo2 += 1
        
        # 3번 수포자의 채점
        if answers[i] == supo3_arr[i%10]:
            supo3 += 1
    
    # dict()으로 정렬해서 가장 큰 점수 가져오기
    max_value = {}
    max_value[1] = supo1
    max_value[2] = supo2
    max_value[3] = supo3
    
    # 정렬
    max_value = sorted(max_value.items(), key=f1, reverse=True)
    max_num = max_value[0][1]
    
    # 가장 큰 값과 값이 비슷하면 result 배열에 넣어줌
    result = []
        
    for i,v in max_value:
        if v == max_num:
            result.append(i)
    
    # result 반환
    return result
    
    
def f1(x):
    return x[1]

댓글남기기