結果

問題 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,548 ms
コンパイル使用メモリ 170,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 09:51:05
合計ジャッジ時間 2,369 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:42:17: warning: 'C' may be used uninitialized [-Wmaybe-uninitialized]
   42 |                 if( C == S[ i ] )
      |                 ^~
main.cpp:12:6: note: 'C' was declared here
   12 | char C;
      |      ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/exception_ptr.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/exception:168,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
In function '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:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/move.h:206:11: warning: 'iPos' may be used uninitialized [-Wmaybe-uninitialized]
  206 |       __b = _GLIBCXX_MOVE(__tmp);
      |           ^
main.cpp: In function 'int main()':
main.cpp:8:5: note: 'iPos' was declared here
    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