코딩테스트

[프로그래머스] 모의고사 - Lv.1

pyflu 2023. 8. 14. 01:35

[프로그래머스] 모의고사 Lv.1 - [파이썬/python]

 

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


 


# 프로그래머스 | 모의고사
def solution(answers):
   
    #1번 수포자 : 1, 2, 3, 4, 5 반복
    student_1 = [1, 2, 3, 4, 5]
   
    #2번 수포자 : 2, 1, 2, 3, 2, 4, 2, 5 반복
    student_2 = [2, 1, 2, 3, 2, 4, 2, 5]
   
    #3번 수포자 : 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 반복
    student_3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
   
    collects = [0,0,0]
    result = []
   
    #정답 하나씩 비교
    for i, answer in enumerate(answers):
       
        #문제의 길이가 더 길수도 있으므로 학생의 패턴을 반복하기
        #문제 정답 맞추면 1씩 더하기
        if student_1[i % len(student_1)] == answer:
            collects[0] += 1
       
        if student_2[i % len(student_2)] == answer:
            collects[1] += 1
           
        if student_3[i % len(student_3)] == answer:
            collects[2] += 1
   
    #collects의 가장 큰 수 찾아서 같으면 result에 num 추가
    for i, collect in enumerate(collects):
        if max(collects) == collect:
            result.append(i+1)
   
    return result

728x90