結果

問題 No.539 インクリメント
ユーザー 14番14番
提出日時 2017-07-01 04:46:12
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,140 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 105,216 KB
実行使用メモリ 44,964 KB
最終ジャッジ日時 2023-07-27 23:23:43
合計ジャッジ時間 3,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

public class Program
{

    public void Proc()
    {
        int inpt = int.Parse(Reader.ReadLine());
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < inpt; i++) {
            ans.AppendLine(Increment(Reader.ReadLine()));
        }
        Console.Write(ans.ToString());


    }

    private string Increment(string str) {
        int fromIdxMax = -1;
        int toIdxMax = -2;

        int fromIdx = -1;
        int toIdx = -1;
        for (int i = 0; i < str.Length; i++) {
            if(str[i]>='0'&&str[i]<='9') {
                if (fromIdx<0) {
                    fromIdx = i;
                }
                toIdx = i;
            } else {
                if (fromIdx >= 0) {
                    fromIdxMax = fromIdx;
                    toIdxMax = toIdx;
                }
                fromIdx = -1;
                toIdx = -1;
            }
        }
		if (fromIdx >= 0)
		{
			fromIdxMax = fromIdx;
			toIdxMax = toIdx;
		}

		if (fromIdxMax>=0) {
            string subStr1 = str.Substring(0, fromIdxMax);
            string subStr2 = str.Substring(toIdxMax + 1);
            long num = long.Parse(str.Substring(fromIdxMax, toIdxMax - fromIdxMax + 1));
            num++;
            return subStr1 + num.ToString().PadLeft(toIdxMax - fromIdxMax+1,'0') + subStr2;
        } else {
            return str;
        }
	}


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"




13
hoge999hoge
73-23=49
O(n^2 log n)
hoge0003871hoge
00000000000000000000000
-0
999
yuki2006
rng_58
sugim48
02/29/2016
D programming language version 0.99
piyo




";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
0