結果

問題 No.39 桁の数字を入れ替え
ユーザー sasa
提出日時 2025-03-06 14:34:03
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 391 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 25,344 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2025-03-06 14:34:06
合計ジャッジ時間 1,509 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:6:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%s",n);
      |         ^~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(void)
{
	char n[11],i,j,tmp,a,b,max,maxNum;
	scanf("%s",n);

	for (i=0;i<9;i++) {
		max = -1;
		for (j=8;j>i;j--) {
			if (n[j] < '0' || n[j] > '9') continue;
			if (max < n[j]) {
				max = n[j];
				maxNum = j;
			}
		}
		
		if (n[i] < max) {
			tmp = n[i];
			n[i] = n[maxNum];
			n[maxNum] = tmp;
			printf("%s\n",n);
			return 0;
		}
	}
	printf("%s\n",n);
}
0