結果

問題 No.2021 Not A but B
ユーザー shisidor
提出日時 2023-04-01 22:36:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 68,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 12:20:15
合計ジャッジ時間 1,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<set>
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int res = 0;
    bool b = false;
    for (int i = 0; i < n - 1; i++) {
        if (b == false && s[i] == 'B' && s[i + 1] == 'B') {
            b = true;
            res++;
        }
        else if (s[i] == 'B' && s[i + 1] == 'B') continue;
        else if (i != 0 && s[i - 1] == 'B' && s[i] == 'A' && s[i + 1] == 'B') continue;
        else res++;
    }
    cout << res << endl;
    return 0;
}
0