-
[1544] 사이클 단어 (Python)[Python] 알고리즘/Silver 2021. 12. 22. 11:39
[문제]
https://www.acmicpc.net/problem/1544
알고리즘 분류는 구현, 자료 구조, 문자열, 브루트포스 알고리즘, 해시를 이용한 집합과 맵 입니다.
deque를 사용하여 한 문자를 뒤로 보내며 검사하였습니다.
[코드]
import sys from collections import deque N = int(sys.stdin.readline()) w_li = list() for i in range(N): w_li.append(sys.stdin.readline().rstrip()) for i in range(N): dq = deque(w_li[i]) while True: dq.append(dq.popleft()) save = "".join(dq) if save == w_li[i]: break if save in w_li: idx = w_li.index(save) w_li.pop(idx) w_li.insert(idx, w_li[i]) w_li = set(w_li) print(len(w_li))
'[Python] 알고리즘 > Silver' 카테고리의 다른 글
[1411] 비슷한 단어 (Python) (0) 2022.03.01 [1972] 놀라운 문자열 (Python) (0) 2021.12.23 [1021] 회전하는 큐 (Python) (0) 2021.12.21 [1543] 문서 검색 (Python) (0) 2021.12.02 [4900] 7 더하기 (Python) (0) 2021.12.01