結果

問題 No.2021 Not A but B
ユーザー Carpenters-Cat
提出日時 2022-07-29 22:01:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 534 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 196,268 KB
最終ジャッジ日時 2025-01-30 15:15:47
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 17 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    string s;
    cin >> s;
    s = "B" + s + "B";
    int ans = 0;
    for (int i = 0; i <= N; i ++) {
        if (s[i] == 'A' || s[i + 1] == 'A') {
            ans ++;
        }
    }
    for (int i = 0; i < N; i ++) {
        if (s.substr(i, 3) == "BAB") {
            ans --;
        }
    }
    for (int i = 1; i < N; i ++) {
        if (s.substr(i, 2) == "BB") {
            ans ++;
            break;
        }
    }
    cout << ans << endl;
}
0