結果
問題 | No.559 swapAB列 |
ユーザー |
|
提出日時 | 2018-01-05 14:58:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 653 bytes |
コンパイル時間 | 723 ms |
コンパイル使用メモリ | 67,972 KB |
最終ジャッジ日時 | 2025-01-05 07:00:46 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 |
ソースコード
#include <iostream>using namespace std;unsigned int swapAB( istream& in ){const auto MAX_LENGTH( 12u );char buffer[ MAX_LENGTH + 1 ];in >> buffer;auto s = string( buffer );auto numberOfMove( 0ul ), indexA( s.length() - 1ul ), indexB( 0ul );auto isFirstTime( true );while ( 1 ) {if ( ( indexA = s.rfind( 'A', isFirstTime ? indexA : indexA - 1 ) ) == string::npos ) break;if ( ( indexB = s.find( 'B', isFirstTime ? indexB : indexB + 1 ) ) == string::npos ) break;if ( indexB < indexA ) numberOfMove += indexA - indexB;isFirstTime = false;}return numberOfMove;}int main(){cout << swapAB( cin ) << endl;return 0;}