프로그래머스/Lv. 1
36. 모의고사
Seohyeong Lee
2024. 7. 14. 17:22
유형 : 구현
풀이 시간 : 15분
def solution(answers):
one = [1, 2, 3, 4, 5]
two = [2, 1, 2, 3, 2, 4, 2, 5]
three = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
x, y, z = 0, 0, 0
for i in range(len(answers)):
if one[0] == answers[i]:
x += 1
if two[0] == answers[i]:
y += 1
if three[0] == answers[i]:
z += 1
one.append(one.pop(0))
two.append(two.pop(0))
three.append(three.pop(0))
res = [x, y, z]
answer = [i+1 for i in range(3) if res[i] == max(res)]
return answer
처음에 똑같이 작성했는데 왜 안됐지..
알고리즘 : queue를 설정하여, 하나씩 대조하며 pop한뒤 뒤에 다시 insert한다.