結果

問題 No.539 インクリメント
ユーザー bluemeganebluemegane
提出日時 2021-05-11 07:31:30
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,705 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 111,908 KB
実行使用メモリ 58,420 KB
最終ジャッジ日時 2023-10-21 11:55:34
合計ジャッジ時間 6,289 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
25,804 KB
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Numerics;
using System.Collections.Generic;
using System;

public class P
{
    public string a1 { get; set; }
    public string a2 { get; set; }
}

public class Hello
{
    public static string pp = "!#$%&";
    static void Main()
    {
        var T = int.Parse(Console.ReadLine().Trim());
        while (T-- > 0)
        {
            var s = Console.ReadLine().Trim();
            var p = getP(s);
            if (p.a2 == "") Console.WriteLine(p.a1);
            else
            {
                var ans = p.a1.Replace(pp, plus1(p.a2));
                Console.WriteLine(ans);
            }
        }
    }
    static string plus1(string s)
    {
        if (s == "") return "";
        var sL = s.Length;
        var a = (BigInteger.Parse(s) + 1).ToString();
        var aL = a.Length;
        if (aL < sL) return new string('0', sL - aL) + a;
        else return a;
    }
    static bool checkNum(char t)
    {
        var t2 = t - '0';
        return t2 >= 0 && t2 <= 9;
    }
    static P getP(string s)
    {

        var sL = s.Length;
        var f = false;
        var res = new List<char>();
        for (int i = sL - 1; i >= 0; i--)
        {
            if (checkNum(s[i])) { res.Add(s[i]); f = true; }
            else if (f)
            {
                res.Reverse();
                var aa2 = string.Join("", res);
                var aa1 = s.Replace(aa2, pp);
                return new P { a1 = aa1, a2 = aa2 };
            }
        }
        if (res.Count() == 0) return new P { a1 = s, a2 = "" };
        res.Reverse();
        var a2 = string.Join("", res);
        var a1 = s.Replace(a2, pp);
        return new P { a1 = a1, a2 = a2 };
    }
}
0