ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

๋ฌธ์ œ ํ’€์ด

 ์ด๋ฆ„์ด ์ฃผ์–ด์งˆ ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด์„ ํ†ตํ•ด ์ •๋ ฌ ํ›„์— ์ด๋ฆ„์„ ์ถœ๋ ฅํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

  • ๋™์ผํ•œ ์ด๋ฆ„์€ ํ•˜๋‚˜๋งŒ ์ถœ๋ ฅํ•œ๋‹ค.
  • ์ด๋ฆ„์˜ ๊ธธ์ด๋ฅผ ์šฐ์„ ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.
  • ๊ธธ์ด๊ฐ€ ๊ฐ™๋‹ค๋ฉด, ์ด๋ฆ„ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

์œ„๋Š” ํŒŒ์ด์ฌ์—์„œ `set`๊ณผ `lambda`๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

T = int(input())

for test_case in range(1, T + 1):
    N = int(input())
    names = [None] * N

    for idx in range(N):
        cur_name = input()
        names[idx] = (cur_name, len(cur_name))

    # set์œผ๋กœ ์ค‘๋ณต ์ œ๊ฑฐ, ์ด๋ฆ„์˜ ๊ธธ์ด๊ฐ€ ์šฐ์„ ์ด ๋˜๋„๋ก ์ •๋ ฌ
    result = sorted(set(names), key=lambda x: (x[1], x[0]))
    print('#{}'.format(T))
    print(*[name for name, _ in result], sep='\n')

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€