結果

問題 No.559 swapAB列
ユーザー mokomoko
提出日時 2017-08-26 07:50:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 158,296 KB
実行使用メモリ 10,012 KB
最終ジャッジ日時 2024-04-23 16:54:38
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,012 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PI;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  if (s.size() == 1) {
    cout << 0 << endl;
  }
  int a = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') a++;
  }
  int ans = 0;
  int pos = 0;
  while (true) {
    bool flag = false;
    for (int i = pos; i < s.size(); i++) {
      if (s[i] == 'B' && s[i+1] == 'A') {
        s[i] = 'A'; s[i+1] = 'B';
        ans++;
        break;
      }
    }
    pos = s.find('B') - 1;
    //cout << s << pos << endl;
    if (pos + 1 == a) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}
0