結果

問題 No.539 インクリメント
ユーザー kuuso1kuuso1
提出日時 2017-07-01 17:07:38
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,044 bytes
コンパイル時間 2,911 ms
コンパイル使用メモリ 113,704 KB
実行使用メモリ 38,960 KB
最終ジャッジ日時 2024-04-15 07:56:47
合計ジャッジ時間 2,143 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
23,808 KB
testcase_01 AC 54 ms
38,776 KB
testcase_02 AC 74 ms
38,884 KB
testcase_03 AC 76 ms
38,960 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using BI = System.Numerics.BigInteger;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		for(int i=0;i<N;i++){
			var s = S[i];
			bool found = false;
			int l = -1,r = -1;
			int nn = s.Length;
			for(int j=nn-1;j>=0;j--){
				if(!found){
					if(InRange(s[j],'0','9'+1)){
						r = j;
						l = j;
						found = true;
						continue;
					} else {
						continue;
					}
				}
				if(found){
					if(InRange(s[j],'0','9'+1)){
						l = j;
						continue;
					} else {
						break;
					}
				}
			}
			
			if(!found){
				Console.WriteLine(s);
				continue;
			}
			
			String left = s.Substring(0,l);
			String mid = s.Substring(l,(r-l+1));
			String right = s.Substring(r+1);
			
			char[] ca = mid.ToCharArray();
			int carry = 1;
			int m = ca.Length;
			for(int j=m-1;j>=0;j--){
				ca[j] = (char)(ca[j] + carry);
				carry = 0;
				if(!InRange(ca[j],'0','9'+1)){
					ca[j] = '0';carry = 1;
				}
			}
			var nmid = carry == 1 ? "1" : "";
			nmid = nmid + new String(ca);
			
			
			Console.WriteLine(left + nmid + right);
		}
	}
	
	bool InRange(int t, int l, int r){
		return l <= t && t < r;
	}
	
	int N;
	String[] S;
	public Sol(){
		N = ri();
		S = new String[N];
		for(int i=0;i<N;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0