結果

問題 No.927 Second Permutation
ユーザー amaridekinai
提出日時 2019-11-24 16:21:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 167,232 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 04:18:09
合計ジャッジ時間 2,158 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  string X; cin >> X; int n = X.size();
  int zero = 0;
  set<char> s;
  for(int i = 0; i < n; i++){
    if(X[i] == '0'){ zero++;} s.insert(X[i]);
  }
  
  if( zero == n-1 || s.size() == 1){ cout << -1 << endl; return 0;}
  //0以外の異なる文字が2つ以上含まれていないとならない
  sort(X.begin(),X.end());
  
  int pos = 0;
  for(int i = 0; i < n; i++){
    if( X[i] == X[0]){ pos = i;}
    else{ swap(X[i],X[pos]); break;}
  }
  
  reverse(X.begin(),X.end());
  
  cout << X << endl; return 0;
}
  
  
0