結果

問題 No.539 インクリメント
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-26 22:52:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 77,052 KB
実行使用メモリ 47,580 KB
最終ジャッジ日時 2024-05-03 20:00:11
合計ジャッジ時間 12,064 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		sc.nextLine();
		int increase = 0;
		boolean isFinished;
		boolean isFirst;
		boolean isDuringSearch;
		StringBuilder ans = new StringBuilder();

		for (int i=0; i<n; i++) {
			char[] ar = sc.nextLine().toCharArray();
			isFinished = false;
			isFirst = true;
			isDuringSearch = false;
			for (int j=ar.length-1; j>=0; j--) {
				if ('0'<=ar[j] & ar[j]<='9') {
					if (isFinished==false) {
						if (isFirst==true) {
							if (ar[j]=='9') {
								increase = 1;
								ar[j] = '0';
								isDuringSearch = true;
							}
							else {
								ar[j]++;
								increase = 0;
								isFinished = true;
							}
							isFirst = false;
						}
						else if (isFirst==false) {
							if (ar[j]=='9') {
								ar[j] = '0';
							}
							else if (ar[j]<'9') {
								ar[j]++;
								increase = 0;
								isFinished = true;
							}
						}
					}
				}
				else {
					if (isDuringSearch==true) {
						isFinished = true;
						isDuringSearch = false;
						if (increase==1) {
							ans.insert(0,'1');
						}
					}
				}
				ans.insert(0,ar[j]);
				
			}
			out.println(ans);
			ans.setLength(0);
		}
	}
}
0