結果

問題 No.39 桁の数字を入れ替え
ユーザー HiroakiSoftwareHiroakiSoftware
提出日時 2014-10-14 23:36:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 04:22:41
合計ジャッジ時間 903 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 0 ms
6,944 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 AC 0 ms
6,940 KB
testcase_09 AC 0 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 0 ms
6,940 KB
testcase_16 AC 0 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%s", NumberStr);
      |         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

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