結果

問題 No.39 桁の数字を入れ替え
コンテスト
ユーザー Himatsubushin
提出日時 2022-12-22 14:52:37
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 674 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 215 ms
コンパイル使用メモリ 38,208 KB
最終ジャッジ日時 2026-02-22 10:01:28
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main(int argc, const char * argv[]) {
  char input[9];
  int number[9], digit, max, pos1, pos2, result;

  scanf("%s", input);
  
  for (digit = 0; input[digit] != '\0'; digit++)
    number[digit] = (int)(input[digit] - '0');

  for (pos1 = max = digit = 0; input[digit] != '\0'; digit++)
    if (number[digit] >= max) {
      max = number[digit];
      pos1 = digit;
    }
  
  for (pos2 = 0; number[pos2] >= max; pos2++);

  result = number[pos2];
  number[pos2] = number[pos1];
  number[pos1] = result;

  for (result = digit = 0; input[digit] != '\0'; digit++)
    result = result * 10 + number[digit];

  printf("%d\n", result);

  return 0;
}
0