結果

問題 No.39 桁の数字を入れ替え
ユーザー HiroakiSoftwareHiroakiSoftware
提出日時 2014-10-14 23:36:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 26,052 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-25 11:27:29
合計ジャッジ時間 1,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
yukicoder No.39
作成者:ヒロソフ
使用言語:C/C++
*/
#include <stdio.h>
#include <string.h>
int StringToInt(char *pszString);
void Swap(char *p1, char *p2);
int main(void) {
	char NumberStr[10];

	scanf("%s", NumberStr);

	int Num = StringToInt(NumberStr);
	int b_Num;
	int length = strlen(NumberStr);

	for (int i = 0; i < length - 1 ; i++) {
		for (int j = i + 1; j < length; j++) {

			Swap(NumberStr + i, NumberStr + j);
			b_Num = StringToInt(NumberStr);
			if (Num < b_Num) Num = b_Num;
			Swap(NumberStr + i, NumberStr + j);

		}
	}

	printf("%d\n", Num);
	return 0;
}

void Swap(char *p1, char *p2) {
	char b = *p1;
	*p1 = *p2;
	*p2 = b;
}

int StringToInt(char *pszString) {
	int no = 0;
	char *pc = pszString;
	while (*pc) {
		no = no * 10 + (9 - ('9' - *pc));
		pc++;
	}
	return no;
}
0