백준 2456 - 나는 학급회장이다 (파이썬)
글 작성자: pental

https://www.acmicpc.net/problem/2456
풀이
투표는 여러 명의 학생들이 진행하며, 각 사람은 1번, 2번, 3번 후보에게 1~3점 중 하나씩 점수를 준다.
- 가장 총점이 높은 사람이 회장이 됨.
- 동점일 경우에는 다음 우선순위로 결정.
- 3점을 더 많이 받은 후보
- 2점을 더 많이 받은 후보
- 그래도 같으면 무효처리 (0)
코드
# 백준 2456 - 나는 학급회장이다 # 분류 : 구현 N = int(input()) score = [0] * 3 count_3 = [0] * 3 count_2 = [0] * 3 for _ in range(N) : s = list(map(int, input().split())) for i in range(3) : score[i] += s[i] if s[i] == 3 : count_3[i] += 1 if s[i] == 2 : count_2[i] += 1 max_score = 0 max_count_3 = 0 max_count_2 = 0 id = -1 for i in range(3) : if max_score < score[i] : max_score = score[i] max_count_3 = count_3[i] max_count_2 = count_2[i] id = i elif max_score == score[i] : if max_count_3 < count_3[i] : max_count_3 = count_3[i] max_count_2 = count_2[i] id = i elif max_count_3 == count_3[i] : if max_count_2 < count_2[i] : max_count_2 = count_2[i] id = i elif max_count_2 == count_2[i] : id = -1 if id == -1 : print(0, max_score) else : print(id + 1, max_score)
'Programming > 백준' 카테고리의 다른 글
[실버 4] 백준 1269 - 대칭 차집합 (파이썬) (0) | 2025.04.02 |
---|---|
백준 2495 - 연속구간 (파이썬) (0) | 2025.04.02 |
백준 2491 - 수열 (파이썬) (0) | 2025.03.31 |
백준 2506 - 점수계산 (파이썬) (0) | 2025.03.30 |
백준 2485 - 가로수 (파이썬) (0) | 2025.03.30 |
댓글
이 글 공유하기
다른 글
-
[실버 4] 백준 1269 - 대칭 차집합 (파이썬)
[실버 4] 백준 1269 - 대칭 차집합 (파이썬)
2025.04.02 -
백준 2495 - 연속구간 (파이썬)
백준 2495 - 연속구간 (파이썬)
2025.04.02 -
백준 2491 - 수열 (파이썬)
백준 2491 - 수열 (파이썬)
2025.03.31 -
백준 2506 - 점수계산 (파이썬)
백준 2506 - 점수계산 (파이썬)
2025.03.30
댓글을 사용할 수 없습니다.