728x90
12871번: 무한 문자열
첫째 줄에 s, 둘째 줄에 t가 주어진다. 두 문자열 s와 t의 길이는 50보다 작거나 같은 자연수이고, 알파벳 소문자로만 이루어져 있다.
www.acmicpc.net
def gcd(x, y):
if x > y:
x, y = y, x
while x > 0:
y, x = x, y % x
return y
def chk(s, t):
tmp = gcd(len(s), len(t))
tmp_s = s*(len(t)//tmp)
tmp_t = t*(len(s)//tmp)
if tmp_t == tmp_s:
return 1
return 0
print(chk(input(), input()))
최소공배수길이로 만들어서 비교하였다.
'STUDY > Algorithm' 카테고리의 다른 글
[백준] 12904 A와B python (0) | 2021.03.26 |
---|---|
[백준] 12967 pqr python 못풀었다. (0) | 2021.03.26 |
[백준] 13706 제곱근 python (1) | 2021.03.25 |
[백준] 12907 동물원 (0) | 2021.03.25 |
[백준] 16953 A->B (0) | 2021.03.25 |