結果

問題 No.927 Second Permutation
ユーザー bluemeganebluemegane
提出日時 2019-11-23 20:40:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 109,308 KB
実行使用メモリ 27,016 KB
最終ジャッジ日時 2024-04-19 14:45:34
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
24,332 KB
testcase_01 AC 23 ms
24,712 KB
testcase_02 AC 25 ms
22,580 KB
testcase_03 AC 25 ms
24,672 KB
testcase_04 AC 25 ms
26,624 KB
testcase_05 AC 24 ms
24,460 KB
testcase_06 AC 24 ms
24,328 KB
testcase_07 AC 25 ms
26,472 KB
testcase_08 AC 30 ms
24,772 KB
testcase_09 AC 25 ms
24,368 KB
testcase_10 AC 34 ms
24,516 KB
testcase_11 AC 41 ms
22,960 KB
testcase_12 AC 32 ms
24,768 KB
testcase_13 AC 26 ms
24,524 KB
testcase_14 AC 35 ms
24,768 KB
testcase_15 AC 32 ms
24,520 KB
testcase_16 AC 44 ms
24,972 KB
testcase_17 AC 45 ms
24,844 KB
testcase_18 AC 43 ms
27,008 KB
testcase_19 AC 42 ms
27,012 KB
testcase_20 AC 43 ms
27,016 KB
testcase_21 AC 42 ms
26,928 KB
testcase_22 AC 42 ms
26,800 KB
testcase_23 AC 43 ms
25,016 KB
testcase_24 AC 38 ms
26,552 KB
testcase_25 AC 33 ms
24,620 KB
testcase_26 AC 32 ms
24,620 KB
testcase_27 AC 29 ms
26,672 KB
testcase_28 AC 35 ms
24,608 KB
testcase_29 AC 35 ms
26,532 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim().ToArray();
        Console.WriteLine(getAns(s));
    }
    static string getAns(char[] s)
    {
        Array.Sort(s);
        for (int i = 0; i < s.Length - 1; i++)
        {
            if (s[i] != s[i + 1])
            {
                var tmp = s[i];
                s[i] = s[i + 1];
                s[i + 1] = tmp;
                if (s[s.Length - 1] != '0')
                {
                    Array.Reverse(s);
                    var ans = new string(s);
                    return ans;
                }
                else return "-1";
            }
        }
        return "-1";
    }
}
0