题解 | 吐泡泡

吐泡泡

https://www.nowcoder.com/practice/f86fa2221c094b3d8d1fc79bae450d96

import sys

T = int(input())
for _ in range(T):
    st = []
    s = input()

    for ch in s:
        if (len(st) != 0 and st[-1] != ch) or len(st) == 0:
            st.append(ch)
        elif ch == 'O':
            st.pop()
        elif ch == 'o':
            st.pop()
            if len(st) != 0:
                st.pop()
            else:
                st.append('O')

    print(''.join(st))

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务