study/swea
[swea] 2007. 패턴 마디의 길이 : python
시즈코
2021. 9. 20. 17:55
반응형
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
패턴 마디의 길이
접근 방법
- for 문으로 숫자를 하나씩 증가시키며 슬라이싱으로 text를 읽는다
- 읽어준 text를 패턴 리스트에 입력한 후 다음 패턴과 비교해준다
- 패턴이 반복되기 시작하면 해당 패턴의 길이를 출력해준다
T = int(input())
for tc in range(1, T+1):
text = input()
patten =[]
next_patten=[]
ans = 0
for i in range(11): # 마디의 최대 길이가 10이므로 range(11)
patten = text[:i] # patten리스트에 패턴 입력
next_patten = text[i:i*2] # 다음 패턴 입력
#print(patten)
#print(next_patten)
if i!=0 and patten == next_patten : # 다음 패턴과 이번 패턴이 같은경우
ans = len(patten) # 길이 출력
break
print('#{} {}'.format(tc, ans))
반응형