結果
問題 | No.39 桁の数字を入れ替え |
ユーザー |
![]() |
提出日時 | 2014-10-14 23:36:17 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 859 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 23,936 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 05:48:37 |
合計ジャッジ時間 | 1,030 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
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); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
/*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;}