๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 20291 - ํŒŒ์ผ ์ •๋ฆฌ

by YWTechIT 2021. 5. 24.
728x90

๐Ÿ“ ๋ฐฑ์ค€ 20291 - ํŒŒ์ผ ์ •๋ฆฌ

๋ฐฑ์ค€ 20291 - ํŒŒ์ผ ์ •๋ฆฌ


โšก๏ธ ๋‚˜์˜ ํ’€์ด

  1. ํ™•์žฅ์ž ๋’ค์˜ ๊ฐ’๋งŒ ๋‹ด์„ defaultdict ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•œ๋‹ค.
  2. ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌ(split())ํ•œ๋‹ค.
  3. ๋™์ผํ•œ ํ™•์žฅ์ž(split()[1])๊ฐ€ ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜ค๋ฉด defaultdict์— 1์”ฉ ๋”ํ•œ๋‹ค.
  4. dic.items()๋ฅผ sortedํ•œ๋‹ค.
  5. ' '.join์„ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅํ•œ๋‹ค.
from collections import defaultdict
import sys
input = sys.stdin.readline

n = int(input())
dic = defaultdict(int)

for _ in range(n):
    file = input().rstrip().split('.')[1]
    dic[file] += 1

for i in sorted(dic.items()):
    print(' '.join(map(str, i)))
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€