์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Python

[BOJ/Step12] 1181 : ๋‹จ์–ด ์ •๋ ฌ (Python)

NaNaRin๐Ÿ™ƒ 2021. 2. 19. 17:30

www.acmicpc.net/problem/1181

 

1181๋ฒˆ: ๋‹จ์–ด ์ •๋ ฌ

์ฒซ์งธ ์ค„์— ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 20,000) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๊ฐ€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 50์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

www.acmicpc.net


์ž…๋ ฅ๋ฐ›์€ N๊ฐœ์˜ ๋‹จ์–ด๋ฅผ ๊ธธ์ด๊ฐ€ ์งง์€ ์ˆœ์œผ๋กœ, ๊ธธ์ด๊ฐ€ ๊ฐ™๋‹ค๋ฉด ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ๋ฌธ์ œ

1. ๊ฐ™์€ ๋‹จ์–ด๊ฐ€ ์ž…๋ ฅ๋˜๋ฉด ํ•œ ๋ฒˆ๋งŒ ์ถœ๋ ฅํ•ด์•ผ ํ•˜๋ฏ€๋กœ setํ˜•์œผ๋กœ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ํ›„ list๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค

2. ์ž…๋ ฅ๋ฐ›์€ ๋‹จ์–ด๋“ค์„ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ •๋ ฌ  => sort()

3. ์ž…๋ ฅ๋ฐ›์€ ๋‹จ์–ด๋“ค์„ ๊ธธ์ด ์ˆœ๋Œ€๋กœ ์ •๋ ฌ  => ๋‚ด์žฅํ•จ์ˆ˜ sorted()

# 1181.py

import sys

n = int(input())
words = list({sys.stdin.readline().strip() for _ in range(n)})
words.sort()
words = sorted(words, key=lambda t: len(t))
for i in words:
    print(i)