[백준] 12919번 A와 B 2- 파이썬/문자열

JinUk Lee·2023년 2월 6일
0

백준 알고리즘

목록 보기
39/78
import sys

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()
count = len(T) - len(S)
T_list = [T]

while count:
    count+=-1
    temt = []

    for t in T_list:
        if t[-1]=='A':
            T_1 = t[:-1]
            temt.append(T_1)
        if t[0]=='B':
            T_2 = t[::-1][:-1]
            temt.append(T_2)

    temt = list(set(temt))
    T_list = temt

    if len(T_list) == 0:
        print(0)
        break

    if len(T_list[0]) == len(S):

        if S in T_list:
            print(1)
            break
        else:
            print(0)
            break

긴 문자열에서 짧은 문자열로 연산방법 두가지를 모두 시행하면서 최종적으로 문자열의 길이가 같아졌을때, 리스트에 S가 있는지 판단하여 문제를 풀었다.

profile
개발자 지망생

0개의 댓글