Codeforces 913 (Div 3) B

B. YetnotherrokenKeoard


Problem : https://codeforces.com/contest/1907/problem/B

Code :

lines = int(input())

for line in range(lines):
    lineData = list(str(input()))
    uc_stack = []
    lc_stack = []
    for char_idx in range(len(lineData)):
        if lineData[char_idx].islower():
            if lineData[char_idx] != "b":
                lc_stack.append(char_idx)
            else:
                lineData[char_idx] = " "
                if len(lc_stack) > 0:
                    lineData[lc_stack.pop()] = " "
        if lineData[char_idx].isupper():
            if lineData[char_idx] != "B":
                uc_stack.append(char_idx)
            else:
                lineData[char_idx] = " "
                if len(uc_stack) > 0:
                    lineData[uc_stack.pop()] = " "

    print("".join([c for c in lineData if c != " "]))
        

Submission link : https://codeforces.com/contest/1907/submission/240033010



© 2024 by Chiranjeevi Karthik