백준 11557 Yangjojang of The Year (구현)

나는야 멋쟁이·2023년 2월 15일
0

학교, 술 양이 주어질 때 가장 많이 마신 학교를 찾는 문제
딕셔너리로 dic[학교] = 술 로 처리함.

test = int(input())

for t in range(test):
    n = int(input())
    dic = {}

    for i in range(n):
        st = input().split(" ")
        s, drink = st[0], int(st[1])
        if s in dic:
            dic[s] += drink
        else:
            dic[s] = drink

    for d in dic.items():
        if max(dic.values()) == d[1]:
            print(d[0])
            break

마지막 for문에서 dic.values를 통해 max값을 찾는다

profile
열심히 개발공부하기

0개의 댓글