문제풀이/SW Expert Academy

[SWEA][D2] 2007. 패턴 마디의 길이 (파이썬/Python)

얄루몬 2021. 8. 24. 16:09

for i in range(int(input())):
    s=input()
    for j in range(1,10): #1
        if s[:j]==s[j:2*j]: #2
            print(f'#{i+1} {j}')
            break
>>> s[:2] 'SA'
>>> s[2:4] 'MS'
>>> s[:3] 'SAM'
>>> s[3:6] 'SUN'
>>> s[:4] 'SAMS'
>>> s[4:8] 'UNGS'
>>> s[:5] 'SAMSU'
>>> s[5:10] 'NGSAM'
>>> s[:6] 'SAMSUN'
>>> s[6:12] 'GSAMSU'
>>> s[:7] 'SAMSUNG'
>>> s[7:14] 'SAMSUNG' >>>