結果

問題 No.1894 Delete AB
ユーザー ぷら
提出日時 2022-04-08 22:06:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 194,880 KB
最終ジャッジ日時 2025-01-28 16:10:32
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 1 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int N;
        string S;
        cin >> N >> S;
        int sum = 0;
        string ans = "",now = "";
        for(int i = 0; i < N; i++) {
            if(S[i] == 'B') {
                sum++;
                if(sum == 1) {
                    ans += 'B';
                    now = "";
                    sum = 0;
                }
                else {
                    now += 'B';
                }
            }
            else {
                sum--;
                now += 'A';
            }
        }
        cout << ans+now << endl;
    }
}
0