본문 바로가기
Algorithm/baekjoon

[파이썬]baekjoon 12904: A와 B

by 갈잃자 2023. 2. 10.

https://www.acmicpc.net/problem/12904

 

12904번: A와 B

수빈이는 A와 B로만 이루어진 영어 단어가 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수

www.acmicpc.net


s와 t를 받아서 s와 t가 같아질 수 있는지 확인하는 문제

 

문제 힌트는, t를 s로 변환시키며 확인하면 더욱 수월하게 풀 수 있다!

s = list(input())
t = list(input())
result = 0
while 1:
    if s ==t:
        result = 1
        break
    if len(s) == len(t) and s != t:
        result = 0
        break
    if t[-1] == 'A':
        t.pop(-1)
        continue

    if t[-1] == 'B':
        t.pop(-1)
        t.reverse()
print(result)

댓글