結果

問題 No.39 桁の数字を入れ替え
ユーザー 14番14番
提出日時 2016-04-03 21:19:42
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 2,179 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 113,196 KB
実行使用メモリ 25,768 KB
最終ジャッジ日時 2024-04-10 05:21:45
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,736 KB
testcase_01 AC 27 ms
23,724 KB
testcase_02 AC 27 ms
23,828 KB
testcase_03 AC 26 ms
25,752 KB
testcase_04 AC 27 ms
25,644 KB
testcase_05 AC 26 ms
21,812 KB
testcase_06 AC 27 ms
25,768 KB
testcase_07 AC 27 ms
23,848 KB
testcase_08 AC 26 ms
25,640 KB
testcase_09 AC 27 ms
23,572 KB
testcase_10 AC 27 ms
23,716 KB
testcase_11 AC 27 ms
23,956 KB
testcase_12 AC 26 ms
23,824 KB
testcase_13 AC 26 ms
23,696 KB
testcase_14 AC 27 ms
23,596 KB
testcase_15 AC 26 ms
23,588 KB
testcase_16 AC 26 ms
23,696 KB
testcase_17 AC 26 ms
23,952 KB
testcase_18 AC 27 ms
23,956 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        string num = Reader.ReadLine();
        List<char> sorted = new List<char>();
        sorted.AddRange(num.ToCharArray());
        sorted.Sort();
        sorted.Reverse();

        int idxFrom = -1;
        int idxTo = -1;
        for (int i = 0; i < sorted.Count - 1; i++)
        {
            if (num[i] != sorted[i])
            {
                idxFrom = i;
                char findFor = sorted[i];
                idxTo = num.LastIndexOf(findFor);
                break;
            }
        }
        char[] arr = num.ToCharArray();
        if (idxFrom >= 0)
        {
            char tmp = arr[idxFrom];
            arr[idxFrom] = arr[idxTo];
            arr[idxTo] = tmp;
        }
        StringBuilder ans = new StringBuilder();
        foreach (char c in arr)
        {
            ans.Append(c);
        }
        Console.WriteLine(ans.ToString());
    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


999999999






 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0