백준 11637번: 인기 투표 #Python

ColorlessDia·2024년 10월 11일

algorithm/baekjoon

목록 보기
327/808
import sys

T = int(sys.stdin.readline())

for _ in range(T):
    n = int(sys.stdin.readline())

    total_vote = 0
    max_vote = 0
    max_vote_count = 0
    candidate_number = 0

    for i in range(1, n + 1):
        vote = int(sys.stdin.readline())

        total_vote += vote

        if max_vote == vote:
            max_vote_count += 1
            continue
        
        if max_vote < vote:
            max_vote = vote
            max_vote_count = 1
            candidate_number = i
            continue
        
    majority_count = (total_vote // 2) + 1

    if 1 < max_vote_count:
        print('no winner')
    elif majority_count <= max_vote:
        print(f'majority winner {candidate_number}')
    elif max_vote < majority_count:
        print(f'minority winner {candidate_number}')

0개의 댓글