[Silver V] Title: ABB to BA (Easy), Time: 56 ms, Memory: 32412 KB -BaekjoonHub

This commit is contained in:
SSUM
2025-04-08 14:13:49 +09:00
parent 68ba0ee008
commit 7e938edc57
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
t = int(input())
for _ in range(t):
n = int(input())
s = list(input())
i = 0
while i <= len(s) - 3:
if s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'B':
s[i], s[i + 1] = 'B', 'A'
s.pop(i + 2)
i = max(i - 2, 0)
else:
i += 1
print(''.join(s))

File diff suppressed because one or more lines are too long