結果

問題 No.539 インクリメント
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-26 16:42:49
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,387 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 78,552 KB
実行使用メモリ 62,296 KB
最終ジャッジ日時 2024-05-03 07:03:33
合計ジャッジ時間 5,682 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
41,640 KB
testcase_01 AC 421 ms
49,056 KB
testcase_02 RE -
testcase_03 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static void solve (String[] ar, int n) {
		String s;
		int start = -1;
		int end = -1;
		StringBuilder sb = new StringBuilder();
		StringBuilder num1 = new StringBuilder();
		StringBuilder num2 = new StringBuilder();
		int leng = 0;

		for (int i=0; i<n; i++) {
			s = ar[i];
			for (int j=s.length(); j>=1; j--) {
				if (end==-1 && s.substring(j-1,j).matches("[0-9]")) {
					end = j;
					start = j;
				}
				if (end!=-1 && s.substring(j-1,j).matches("[0-9]")==false) {
					break;
				}
				if (end!=-1 && s.substring(j-1,j).matches("[0-9]")) {
					start--;
				}
			}

			if (start==-1 && end==-1) {
				System.out.println(s);
			}
			else {
				sb.append(s);
				sb.delete(start,end);
				num1.append(s.substring(start,end));
				num2.append(Integer.parseInt(s.substring(start,end))+1);
				if (num2.length() < num1.length()) {
					leng = num1.length()-num2.length();
					for (int k=0; k<leng; k++) {
						num2.insert(0,"0");
					}
				}
				sb.insert(start,num2);
				System.out.println(sb);
			}
			start = -1;
			end = -1;
			sb.setLength(0);
			num1.setLength(0);
			num2.setLength(0);
		}
	}
	public static void main(String[] args) {
		int n = sc.nextInt();
		sc.nextLine();
		String[] ar = new String[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextLine();
		}
		solve(ar,n);
	}
	static Scanner sc = new Scanner(System.in);
}
0