結果

問題 No.559 swapAB列
ユーザー GB
提出日時 2018-10-28 15:58:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 54,528 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-19 07:04:49
合計ジャッジ時間 1,034 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>

using namespace std;

int main() {
	string str;
	cin >> str;
	if (str.size() == 1) {
		cout << 0;
		return 0;
	}

	int now = 0;
	int count = 0;
	while(now!=str.size()-1){
		if (str[now] == 'A') {
			now++;
			continue;
		}
		else if (str[now] == 'B') {
			if (str[now + 1] == 'A') {
				char tmp = str[now];
				str[now] = str[now + 1];
				str[now + 1] = tmp;
				now = 0;
				count++;
				continue;
			}
			now++;
		}
	}

	cout << count;

	return 0;
}
0