์ตœ๋Œ€ 1 ๋ถ„ ์†Œ์š”

๋ฐฑ์ค€ ์‚ฌ์ดํŠธ ๋งํฌ

๋ฌธ์ œ

์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ N๊ฐœ์˜ ๋‹จ์–ด๊ฐ€ ๋“ค์–ด์˜ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์กฐ๊ฑด์— ๋”ฐ๋ผ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

  1. ๊ธธ์ด๊ฐ€ ์งง์€ ๊ฒƒ๋ถ€ํ„ฐ
  2. ๊ธธ์ด๊ฐ€ ๊ฐ™์œผ๋ฉด ์‚ฌ์ „ ์ˆœ์œผ๋กœ

๋‹จ, ์ค‘๋ณต๋œ ๋‹จ์–ด๋Š” ํ•˜๋‚˜๋งŒ ๋‚จ๊ธฐ๊ณ  ์ œ๊ฑฐํ•ด์•ผ ํ•œ๋‹ค.

์ž…๋ ฅ

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

์ถœ๋ ฅ

์กฐ๊ฑด์— ๋”ฐ๋ผ ์ •๋ ฌํ•˜์—ฌ ๋‹จ์–ด๋“ค์„ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

13
but
i
wont
hesitate
no
more
no
more
it
cannot
wait
im
yours

์˜ˆ์ œ ์ถœ๋ ฅ 1

i
im
it
no
but
more
wait
wont
yours
cannot
hesitate

๋ฌธ์ œ๋ฅผ ํ’€๋ฉด์„œ ๋ง‰ํ˜”๋˜ ๋ถ€๋ถ„

์ค‘๋ณต์„ ์—†์• ๊ธฐ ์œ„ํ•ด set์ž๋ฃŒํ˜•์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

์ฝ”๋“œ

ver(1)
import sys

n = int(sys.stdin.readline())
word = list(set(str(sys.stdin.readline().strip()) for _ in range(n)))
word.sort() 
word.sort(key=lambda x: len(x))
for i in word:
    print(i)
ver(2)
import sys

n = int(sys.stdin.readline())
A = list(sys.stdin.readline().strip() for _ in range(n))

A = list(set(A))
A.sort()
A.sort(key = len) 
for i in A:
    print(i)

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ