https://school.programmers.co.kr/learn/courses/30/lessons/42840
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
def solution(answers):
first = [1,2,3,4,5]
second = [2,1,2,3,2,4,2,5]
third = [3,3,1,1,2,2,4,4,5,5]
first_cnt, second_cnt, third_cnt = 0,0,0
for i in range(len(answers)):
if answers[i] == first[i%5]:
first_cnt += 1
if answers[i] == second[i%8]:
second_cnt += 1
if answers[i] == third[i%10]:
third_cnt += 1
answer = []
max_score = max(first_cnt,second_cnt,third_cnt)
if first_cnt == max_score:
answer.append(1)
if second_cnt == max_score:
answer.append(2)
if third_cnt == max_score:
answer.append(3)
return answer
더 깔끔한 다른사람의 풀이
def solution(answers):
pattern1 = [1,2,3,4,5]
pattern2 = [2,1,2,3,2,4,2,5]
pattern3 = [3,3,1,1,2,2,4,4,5,5]
score = [0, 0, 0]
result = []
for idx, answer in enumerate(answers):
if answer == pattern1[idx%len(pattern1)]:
score[0] += 1
if answer == pattern2[idx%len(pattern2)]:
score[1] += 1
if answer == pattern3[idx%len(pattern3)]:
score[2] += 1
for idx, s in enumerate(score):
if s == max(score):
result.append(idx+1)
return result
'프로그래머스' 카테고리의 다른 글
프로그래머스 42839. 소수 찾기 (0) | 2024.11.19 |
---|---|
프로그래머스 42842. 카펫 (0) | 2024.11.17 |
프로그래머스 77486. 다단계 칫솔 판매 (0) | 2024.11.05 |
프로그래머스 84512. 모음사전 (0) | 2024.11.04 |
프로그래머스 43236. 징검다리 (0) | 2024.11.03 |