import sys

n = int(input())
inputs = list(set(sys.stdin.readlines()))

#inputs.sort()
#inputs.sort(key=len)
# len(x)로 정렬 후 원래 sort() 기준으로(x) 정렬
inputs.sort(key=lambda x: (len(x), x))

for word in inputs:
    #print(word)
    print(word.strip())

 

* strip()으로 출력해야하는 이유

: sys.stdin.readlines()로 읽은 각 줄에는 줄바꿈 문자(\n)가 포함되어 있음

 print 함수는 기본적으로 줄바꿈 문자를 추가하기 때문에 줄바꿈이 두 번 들어가게 되어 출력 형식이 잘못될 수 있음!!

 ex) ['more\n', 'wait\n', 'no\n', 'i\n', 'wont\n', 'cannot\n', 'it\n', 'im\n', 'yours\n', 'but\n', 'hesitate\n']

    > 이렇게 \n이 다 포함되어 있어서 strip()으로 없애줘야함... 

'HELLO WORLD > BAEKJOON' 카테고리의 다른 글

백준 | 9012 괄호  (0) 2025.01.18
백준 | 16916 부분 문자열  (0) 2025.01.18
백준 | 1026 보물  (0) 2025.01.18
백준 | 11399 ATM  (0) 2025.01.18
백준 | 9656 돌 게임 2  (0) 2025.01.18

+ Recent posts