結果
| 問題 | 
                            No.559 swapAB列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             moko_freedom
                         | 
                    
| 提出日時 | 2017-08-26 08:00:02 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 639 bytes | 
| コンパイル時間 | 1,623 ms | 
| コンパイル使用メモリ | 159,748 KB | 
| 実行使用メモリ | 13,644 KB | 
| 最終ジャッジ日時 | 2024-10-15 17:26:03 | 
| 合計ジャッジ時間 | 5,176 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | TLE * 1 -- * 6 | 
ソースコード
#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;
  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 = 0; 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;
}
            
            
            
        
            
moko_freedom