본문 바로가기
python-algorithm

백준 2456 나는 학급회장이다

by 무적김두칠 2022. 10. 29.

https://www.acmicpc.net/problem/2456

 

2456번: 나는 학급회장이다

첫째 줄에는 반의 학생들의 수 N (3 ≤ N ≤ 1,000)이 주어진다. 다음 N개의 각 줄에는 각 학생이 제출한 회장후보 3명에 대한 선호 점수가 주어지는 데, 첫 번째 점수는 후보 1번에 대한 점수이고 두

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
first,second,third=[],[],[]
n=int(input())
for i in range(n):
    a,b,c=map(int, input().split())
    first.append(a)
    second.append(b)
    third.append(c)
first = [sum(first), first.count(3), first.count(2), first.count(1),1]
second = [sum(second), second.count(3), second.count(2), second.count(1),2]
third = [sum(third), third.count(3), third.count(2), third.count(1),3]
answer=[first,second,third]
answer.sort(key= lambda x: (x[0],x[1],x[2]), reverse=True)
 
if answer[0][:4]==answer[1][:4]:
    print(0,answer[0][0])
else:
    print(answer[0][4],answer[0][0])
cs

정렬과 카운팅을 통해 풀었습니다
Use Sort, count

반응형

'python-algorithm' 카테고리의 다른 글

백준 13322 접두사 배열  (0) 2022.10.29
백준 9455 박스  (0) 2022.10.29
백준 4641 Doubles  (0) 2022.10.29
백준 13235 팰린드롬  (0) 2022.10.28
백준 14696 딱지놀이  (0) 2022.10.28

댓글