結果

問題 No.927 Second Permutation
ユーザー michonz4michonz4
提出日時 2019-12-28 23:02:40
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,001 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 20:19:29
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 14 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 26 ms
5,376 KB
testcase_11 AC 48 ms
5,376 KB
testcase_12 AC 20 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 27 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 54 ms
5,376 KB
testcase_17 AC 55 ms
5,376 KB
testcase_18 AC 55 ms
5,376 KB
testcase_19 AC 54 ms
5,376 KB
testcase_20 AC 53 ms
5,376 KB
testcase_21 AC 54 ms
5,376 KB
testcase_22 AC 53 ms
5,376 KB
testcase_23 AC 52 ms
5,376 KB
testcase_24 AC 1,001 ms
5,376 KB
testcase_25 AC 439 ms
5,376 KB
testcase_26 AC 226 ms
5,376 KB
testcase_27 AC 131 ms
5,376 KB
testcase_28 AC 904 ms
5,376 KB
testcase_29 AC 575 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compareD(const void *a, const void *b) {
  return strcmp((const char *)b, (const char *)a);
}

int main() {
  char x[1000000000];
  scanf("%s", x);

  int size=strlen(x);
  qsort(x, size, sizeof(char), compareD);

  if (x[0]==x[size-1] || x[1]=='0') {
    printf("-1\n");
    return 0;
  } else {
    for (int i=size-1; i>=0; i--) {
      char tmp;
      if (x[i]!='0' && i==size-1) {
        tmp=x[i];
        x[i]=x[i-1];
        x[i-1]=tmp;
        break;
      } else if (x[i]!='0') {
        tmp=x[i];
        x[i]=x[i+1];
        x[i+1]=tmp;
        break;
      }
    }
    printf("%s\n", x);
  }
  return 0;
}
0