結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 2020-12-04 14:25:31 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 578 ms / 2,000 ms |
コード長 | 1,629 bytes |
コンパイル時間 | 2,246 ms |
コンパイル使用メモリ | 77,292 KB |
実行使用メモリ | 56,324 KB |
最終ジャッジ日時 | 2024-09-15 00:42:47 |
合計ジャッジ時間 | 5,271 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = Integer.parseInt(sc.nextLine());StringBuilder sb = new StringBuilder();for (int i = 0; i < n; i++) {char[] arr = sc.nextLine().toCharArray();boolean isNum = false;StringBuilder ans = new StringBuilder();StringBuilder num = new StringBuilder();StringBuilder tmp = new StringBuilder();for (char c : arr) {if (c >= '0' && c <= '9') {if (!isNum) {ans.append(num).append(tmp);num.setLength(0);tmp.setLength(0);isNum = true;}num.append(c);} else {isNum = false;tmp.append(c);}}boolean isAdd = true;for (int j = num.length() - 1; j >= 0; j--) {if (isAdd) {if (num.charAt(j) == '9') {num.setCharAt(j, '0');} else {num.setCharAt(j, (char)(num.charAt(j) + 1));isAdd = false;break;}}}if (isAdd && num.length() > 0) {num.insert(0, '1');}sb.append(ans).append(num).append(tmp).append("\n");}System.out.print(sb);}}