백준 1181

김당찬·2022년 4월 17일
0

문제 : https://www.acmicpc.net/problem/1181
아이디어 :

  • 최대길이만큼 리스트 생성, 각 길이 인덱스에 단어를 별도로 저장
  • [[]]*50 대신 [[] for _ in range(50)] 이용 >> 곱연산 처리하면 내부 리스트들이 모두 복사된 것으로 처리되어 append가 개별적으로 불가❗️
import sys
N = int(sys.stdin.readline()) # 단어개수
length = [[] for _ in range(50)] # 핵심! [[]]*50 으로 하면 반복됨
for i in sys.stdin.readlines():
    i = i.strip()
    length[len(i)-1].append(i)
for j in range(50):
    if len(length[j]) > 0:
        words = sorted(list(set(length[j]))) # 중복제거
        print(*words, sep="\n")
profile
블로그 이사했습니다 https://ddangchani.github.io

0개의 댓글