結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 2017-07-01 17:07:38 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 2,044 bytes |
コンパイル時間 | 871 ms |
コンパイル使用メモリ | 113,340 KB |
実行使用メモリ | 39,104 KB |
最終ジャッジ日時 | 2024-10-04 23:38:25 |
合計ジャッジ時間 | 2,089 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));}}