結果

問題 No.539 インクリメント
ユーザー takeya_okinotakeya_okino
提出日時 2019-10-01 22:48:11
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,303 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 89,304 KB
実行使用メモリ 71,216 KB
最終ジャッジ日時 2024-04-14 08:41:12
合計ジャッジ時間 7,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import java.util.*;
import java.math.BigDecimal;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();
    String line = sc.nextLine();
    for(int i = 0; i < T; i++) {
      String s = sc.nextLine();
      String s1 = "";
      String s2 = "";
      String num = "";
      int p = 0;
      int a = 0;
      for(int j = s.length() - 1; j >= 0; j--) {
        String str = String.valueOf(s.charAt(j));
        int t = -1;
        try {
          t = Integer.parseInt(str);
        } catch(NumberFormatException e) {
        }
        if(t == -1) {
          if(a == 1) p = 1;
          if(p == 0) {
            s2 = str + s2;
          } else {
            s1 = str + s1;
          }
        } else {
          if(p == 0) {
            a = 1;
            num = str + num;
          } else {
            s1 = str + s1;
          }
        }
      }
      if(!(num.equals(""))) {
        BigDecimal d = new BigDecimal(num);
        d = d.add(new BigDecimal(1));
        String ds = d.toString();
        int len = ds.length();
        for(int j = 0; j < num.length() - len; j++) {
          ds = "0" + ds;
        }
        System.out.println(s1 + ds + s2);
      } else {
        System.out.println(s1 + s2);
      }
    }
  }
}
0