結果

問題 No.927 Second Permutation
ユーザー MJXzkibvOFVxZkxMJXzkibvOFVxZkx
提出日時 2019-11-22 22:02:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 671 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 160,332 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-19 11:27:39
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,752 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    string s,copy;
    cin>>s;
    copy=s;
    int si=s.size(),count=0;
    for(int i=0;i<si;i++){
        if(s[i]=='0'){
            count++;
        }
        for(int j=i+1;j<si;j++){
            if(s[i]<s[j]){
                swap(s[i],s[j]);
            }
        }
    }
    swap(s[si-1],s[si-2]);
    if(s==copy || count==si-1){
        cout<<-1<<'\n';
    }
    else if(s[0]=='0'){
        for(int i=0;i<si;i++){
            if(s[i]!='0'){
                swap(s[0],s[i]);
                break;
            }
        }
        cout<<s<<'\n';
    }
    else{
        cout<<s<<'\n';
    }

	return 0;
}
  
0