結果

問題 No.927 Second Permutation
ユーザー jnarutoj
提出日時 2019-11-22 21:49:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 550 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 159,072 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-11 03:19:14
合計ジャッジ時間 2,192 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int fre[10];
    for(int i=0;i<10;i++)fre[i]=0;
    int n=s.length();
    for(int i=0;i<n;i++){
        fre[s[i]-'0']++;
    }
    string res;
    for(int i=9;i>=0;i--){
        while(fre[i]--)res+=char(i+'0');
    }
    int id=-1;
    for(int i=n-2;i>=0;i--){
        if(res[i]!=res[i+1]){
            id=i;
            break;
        }
    }
    if(id==-1){cout<<-1;return 0;}
    else swap(res[id],res[n-1]);
    if(res[0]!='0')cout<<res;
    else cout<<-1;
}
0