結果

問題 No.39 桁の数字を入れ替え
ユーザー skewesskewes
提出日時 2016-01-01 22:50:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 868 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 112,208 KB
実行使用メモリ 25,804 KB
最終ジャッジ日時 2024-04-10 05:16:38
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
23,524 KB
testcase_01 AC 21 ms
25,572 KB
testcase_02 AC 21 ms
25,564 KB
testcase_03 AC 21 ms
23,788 KB
testcase_04 AC 21 ms
25,672 KB
testcase_05 AC 20 ms
21,812 KB
testcase_06 AC 22 ms
25,804 KB
testcase_07 AC 22 ms
25,804 KB
testcase_08 AC 22 ms
25,452 KB
testcase_09 AC 21 ms
23,740 KB
testcase_10 AC 21 ms
23,792 KB
testcase_11 AC 21 ms
25,788 KB
testcase_12 AC 22 ms
25,672 KB
testcase_13 AC 21 ms
23,776 KB
testcase_14 AC 20 ms
23,980 KB
testcase_15 AC 22 ms
23,856 KB
testcase_16 AC 21 ms
25,420 KB
testcase_17 AC 22 ms
23,620 KB
testcase_18 AC 19 ms
23,656 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace yukicoder
{
    class _039
    {
        static void Main()
        {
            string n = Console.ReadLine();
            for (int i = 0; i < n.Length; i++)
            {
                int a = int.Parse(n[i].ToString());
                int m = 0, p = 0;
                for (int j = i + 1; j < n.Length; j++)
                {
                    int b = int.Parse(n[j].ToString());
                    if(a < b && m <= b)
                    {
                        m = b;
                        p = j;
                    }
                }
                if (m != 0)
                {
                    n = n.Substring(0, i) + n[p] + n.Substring(i + 1, p - i - 1)
                        + n[i] + n.Substring(p + 1);
                    break;
                }
            }
            Console.WriteLine(n);
        }
    }
}
0