Algorithm/COS
[COS Pro 1급, Python] 1차 8번 : 누가 당선 되나요
JMcunst
2022. 2. 24. 21:54
728x90
반응형
문제 유형
한줄 수정
난이도
easy
Note
1. 후보 번호 = idx
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
def solution(N, votes):
vote_counter = [0 for i in range(N+1)]
for i in votes:
vote_counter[i] += 1
max_val = max(vote_counter)
print(vote_counter)
answer = []
for idx in range(1, N + 1):
if vote_counter[idx] == max_val:
answer.append(idx)
return answer
N1 = 5
votes1 = [1,5,4,3,2,5,2,5,5,4]
ret1 = solution(N1, votes1)
print("solution 함수의 반환 값은", ret1, "입니다.")
N2 = 4
votes2 = [1, 3, 2, 3, 2]
ret2 = solution(N2, votes2)
print("solution 함수의 반환 값은", ret2, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형