結果

問題 No.927 Second Permutation
ユーザー yicode
提出日時 2023-06-12 13:16:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 1,379 ms
コンパイル使用メモリ 170,220 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-11 15:33:41
合計ジャッジ時間 2,380 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
  string S; cin >> S;
  sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  
  int count = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[0] == S[i]) {
      count++;
    }
  }
  int zero = 0;
  for(int i = 1;i < S.size(); i++) {
    if('0' == S[i]) {
      zero++;
    }
  }
  if(S[S.size() - 1] == S[S.size() - 2]) {
    cout << -1 << endl;
    return 0;
  }
  swap(S[S.size()-1],S[S.size() - 2]);
  if(count == S.size() || zero == S.size() - 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << S << endl;
}
0