結果

問題 No.539 インクリメント
ユーザー takeya_okinotakeya_okino
提出日時 2017-09-23 19:17:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,336 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 79,884 KB
実行使用メモリ 55,276 KB
最終ジャッジ日時 2024-04-26 15:40:26
合計ジャッジ時間 6,288 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    for(int i = 0; i < t; i++) {
      String s = sc.next();
      int flg = 0;
      int keizoku = 0;
      int kuriage = 0;
      int hatsu = 0;
      String ans = "";
      for(int j = s.length() - 1; j >= 0; j--) {
        String str = String.valueOf(s.charAt(j));
        if(flg == 0) {
          try{
            int d = Integer.parseInt(str);
            keizoku = 1;
            if(hatsu == 0) { 
              hatsu = 1;
              if(d + 1 < 10) {
                ans = (d + 1) + ans;
                flg = 1;
              } else {
                ans = "0" + ans;
                kuriage = 1;
              }
            } else {
              if(d + kuriage < 10) {
                ans = (d + kuriage) + ans;
                flg = 1;
              } else { 
                ans = "0" + ans;
                kuriage = 1;
              }
            }
          } catch(NumberFormatException e) {
            if(keizoku == 1 && kuriage > 0) {
              ans = "1" + ans;
            }
            ans = str + ans;
            if(keizoku == 1) flg = 1;
          }
        } else {
          ans = str + ans;
        }
      }
      System.out.println(ans);
    }
  }
}
0