[프로그래머스] 모의고사 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
'코딩테스트' 카테고리의 다른 글
[프로그래머스] 핸드폰 번호 가리기 - Lv.1 (24) | 2023.08.14 |
---|---|
[프로그래머스] 하샤드 수 - Lv.1 (22) | 2023.08.14 |
[프로그래머스] 폰켓몬 - Lv.1 (21) | 2023.08.14 |
[프로그래머스] K번째수 - Lv.1 (27) | 2023.08.14 |
[프로그래머스] 두 개 뽑아서 더하기 - Lv.1 (19) | 2023.08.13 |