結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
Tsukasa_Type
|
| 提出日時 | 2018-02-26 23:17:17 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 433 ms / 2,000 ms |
| コード長 | 1,362 bytes |
| コンパイル時間 | 1,956 ms |
| コンパイル使用メモリ | 77,184 KB |
| 実行使用メモリ | 58,228 KB |
| 最終ジャッジ日時 | 2024-11-25 00:55:08 |
| 合計ジャッジ時間 | 4,254 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
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 isSearch;
StringBuilder ans = new StringBuilder();
for (int i=0; i<n; i++) {
char[] ar = sc.nextLine().toCharArray();
isFinished = false;
isFirst = true;
isSearch = 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';
isSearch = 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;
}
}
if (j==0 && increase==1) {ans.append("01"); break;}
}
}
else {
if (isSearch==true) {
isFinished = true;
isSearch = false;
if (increase==1) {
ans.append(1);
increase = 0;
}
}
}
ans.append(ar[j]);
}
ans.reverse();
out.println(ans);
ans.setLength(0);
}
}
}
Tsukasa_Type