結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-07-01 04:44:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,238 bytes |
| コンパイル時間 | 977 ms |
| コンパイル使用メモリ | 113,132 KB |
| 実行使用メモリ | 49,808 KB |
| 最終ジャッジ日時 | 2024-10-05 03:06:17 |
| 合計ジャッジ時間 | 1,494 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 1 RE * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 && toIdx - fromIdx >= toIdxMax - fromIdxMax) {
fromIdxMax = fromIdx;
toIdxMax = toIdx;
}
fromIdx = -1;
toIdx = -1;
}
}
if (fromIdx>=0 && toIdx - fromIdx >= toIdxMax - fromIdxMax)
{
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();
}
}
14番