結果

問題 No.39 桁の数字を入れ替え
ユーザー 西尾西尾
提出日時 2018-03-20 18:08:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 549 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 167,068 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 15:26:45
合計ジャッジ時間 2,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:42:17: 警告: ‘C’ may be used uninitialized [-Wmaybe-uninitialized]
   42 |                 if( C == S[ i ] )
      |                 ^~
main.cpp:12:6: 備考: ‘C’ はここで定義されています
   12 | char C;
      |      ^
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/exception_ptr.h:43,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/exception:168,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ios:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:1:
関数 ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = char]’ 内,
    inlined from ‘int main()’ at main.cpp:44:8:
/usr/local/gcc7/include/c++/12.2.0/bits/move.h:206:11: 警告: ‘iPos’ may be used uninitialized [-Wmaybe-uninitialized]
  206 |       __b = _GLIBCXX_MOVE(__tmp);
      |           ^
main.cpp: 関数 ‘int main()’ 内:
main.cpp:8:5: 備考: ‘iPos’ はここで定義されています
    8 | int iPos;
      |     ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
int i;
int iLen;
int iPos;
int iPos2;
char S[ 12 ];
char T[ 12 ];
char C;
char cMax;

	cin >> S;

	iLen = strlen( S );
	strcpy( T, S );
	
	sort( T, T + iLen, greater<char>() );

	for( i = 0; i < iLen; i++ )
	{
		if( T[ i ] != S[ i ] )
		{
			iPos = i;
			C = T[ i ];

			break;
		}
	}

	if( i == iLen )
	{
		cout << S << endl;

		return 0;
	}

	for( i = iLen - 1; i > iPos; i-- )
	{
		if( C == S[ i ] )
		{
			swap( S[ i ], S[ iPos ] );

			break;
		}
	}

	cout << S << endl;

	return 0;
}
0