結果
| 問題 | No.39 桁の数字を入れ替え |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-20 18:08:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
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;
| ^~~~
ソースコード
#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;
}