스파르탄 365 5주차 (2) 카드
참고사이트: dict사용해서 최대값의 키 찾기
5주차
백준 11652번 카드
문제링크 : https://www.acmicpc.net/problem/11652
💡 풀이 중 고민
- dict 자료형을 사용하고 싶다
- 사용했는 데 틀렸다 왤까?
! 해결 방법
- dict은 입력한 순서대로 들어가서 모든 값이 같은 경우 가장 앞에 수가 나온다
- 조건에서는 가장 작은 값이 나오길 바람.
! 정렬 하니 타입이 list으로 변경되어 get함수를 사용할 수 없었다
!! 정렬 후 dict으로 형변환을 한 번 해주었다.
!! 스킬
counter = dict(sorted(counter.items()))
max(counter, key=counter.get)
깨달음
: 타입에 신경쓰면서 코딩할 것
풀이
import sys
import collections
input = sys.stdin.readline
N = int(input())
cardList = []
for _ in range(N):
cardList.append(int(input()))
counter = collections.Counter(cardList)
counter = dict(sorted(counter.items()))
# print(counter)
print(max(counter, key=counter.get))
Author And Source
이 문제에 관하여(스파르탄 365 5주차 (2) 카드), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dawnofspring/스파르탄-365-5주차-2-카드저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)