Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- graph
- C
- 생활코딩
- 따라하면서 배우는 C언어
- programmers
- Algospot
- BFS
- 정수론
- Cleancode
- Algorithm
- udemy
- sorting
- web
- 인프런
- dfs
- DP
- 종만북
- Python
- String
- 따라하며 배우는 C언어
- Math
- C언어
- greedy
- JavaScript
- BASIC
- BOJ
- 백준
- server
- php
- 따배씨
Archives
- Today
- Total
몽상실현개발주의
[BOJ] 11652 / 카드 / Python 파이썬 본문
[BOJ] 11652 / 카드 / Python 파이썬
https://www.acmicpc.net/problem/11652
11652번: 카드
준규는 숫자 카드 N장을 가지고 있다. 숫자 카드에는 정수가 하나 적혀있는데, 적혀있는 수는 -262보다 크거나 같고, 262보다 작거나 같다. 준규가 가지고 있는 카드가 주어졌을 때, 가장 많이 가지
www.acmicpc.net
풀이
중복 되는 숫자의 갯수를 처리하기 위하여 Dictionary 를 사용하였다.
그리고 조건에 맞추어 정렬하기 위하여, Dictionary 의 key 와 value 를 tuple 로 받아오는 items() method 와
Lambda 를 사용 하였다.
Python Dictionary items()
The items() method returns a view object that displays a list of dictionary's (key, value) tuple pairs.
sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }
print(sales.items())
-> dict_items([('apple', 2), ('orange', 3), ('grapes', 4)])
import sys
N = int(sys.stdin.readline())
nums = {}
for _ in range(N):
num = int(sys.stdin.readline())
if num not in nums:
nums[num] = 1
else:
nums[num] += 1
nums = sorted(nums.items(), key = lambda x: (x[1], -x[0]))
print(nums[-1][0])
※ sorted() 의 return 은 Array 이므로, dictionary 에서 tuple 을 원소로 갖는 Array 로 정렬되어 반환 된다.
'Algorithm PS > BOJ' 카테고리의 다른 글
[BOJ] 10828 / 스택 / Python 파이썬 (0) | 2021.05.23 |
---|---|
[BOJ] 11004 / K 번째 수 / Python 파이썬 (0) | 2021.05.23 |
[BOJ] 10989 / 수 정렬하기 3 / Python 파이썬 (0) | 2021.05.21 |
[BOJ] 10825 / 국영수 / Python 파이썬 (0) | 2021.05.21 |
[BOJ] 10814 / 나이순 정렬 / Python 파이썬 (0) | 2021.05.21 |
Comments