結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  Tsukasa_Type | 
| 提出日時 | 2018-02-26 17:49:16 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,836 bytes | 
| コンパイル時間 | 2,682 ms | 
| コンパイル使用メモリ | 79,636 KB | 
| 実行使用メモリ | 63,828 KB | 
| 最終ジャッジ日時 | 2024-11-24 09:50:08 | 
| 合計ジャッジ時間 | 8,849 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 1 TLE * 2 | 
ソースコード
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;
		boolean F = true;
		
		for (int i=0; i<n; i++) {
			s = ar[i];
			for (int j=s.length(); j>=1; j--) {
				F = isNumber(s.substring(j-1,j));
				
				if (end==-1 && F==true) {
					end = j;
					start = j;
				}
				if (end!=-1 && F==false) {
					break;
				}
				if (end!=-1 && F==true) {
					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(increment(s.substring(start,end)));
				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);
		}
	}
	static StringBuilder increment (String s) {
		StringBuilder ans = new StringBuilder();
		int up = 1;
		int temp = 0;
		for (int i=s.length()-1; i>=0; i--) {
			temp = up + Character.getNumericValue(s.charAt(i));
			ans.insert(0,temp%10);
			up = temp/10;
		}
		if (up!=0) {ans.insert(0,up);}
		return ans;
	}
	static boolean isNumber(String s) {
	    try {
	        Integer.parseInt(s);
	        return true;
	    } catch (NumberFormatException e) {
	        return false;
	    }
	}
	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);
}
            
            
            
        