-
[프로그래머스] 모의고사Engineering WIKI/Programmers 2022. 4. 1. 02:40
코딩테스트 연습 - 모의고사
수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는
programmers.co.kr
내 풀이
def solution(answers): person1 = [1, 2, 3, 4, 5] person2 = [2, 1, 2, 3, 2, 4, 2, 5] person3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] result = [0, 0, 0] answer_result = [] for idx, answer in enumerate(answers): if answer == person1[idx % len(person1)]: result[0] += 1 if answer == person2[idx % len(person2)]: result[1] += 1 if answer == person3[idx % len(person3)]: result[2] += 1 for idx, score in enumerate(result): if score == max(result): answer_result.append(idx + 1) return answer_result
다른 방법
from itertools import cycle def solution(answers): giveups = [ cycle([1,2,3,4,5]), cycle([2,1,2,3,2,4,2,5]), cycle([3,3,1,1,2,2,4,4,5,5]), ] scores = [0, 0, 0] for num in answers: for i in range(3): if next(giveups[i]) == num: scores[i] += 1 highest = max(scores) return [i + 1 for i, v in enumerate(scores) if v == highest]
'Engineering WIKI > Programmers' 카테고리의 다른 글
[프로그래머스] 예산 (0) 2022.04.05 [프로그래머스] 3진법 뒤집기 (0) 2022.04.05 [프로그래머스] 실패율 (0) 2022.04.02 [프로그래머스] 폰켓몬 (1) 2022.04.01 [프로그래머스] 소수 만들기 (0) 2022.04.01 [프로그래머스] 내적 (1) 2022.04.01 [프로그래머스] 음양 더하기 (0) 2022.04.01 [프로그래머스] 없는 숫자 더하기 (0) 2022.04.01