結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  tktk_snsn | 
| 提出日時 | 2021-01-17 22:53:25 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 752 ms / 2,000 ms | 
| コード長 | 1,044 bytes | 
| コンパイル時間 | 293 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 12,708 KB | 
| 最終ジャッジ日時 | 2024-11-30 04:47:48 | 
| 合計ジャッジ時間 | 2,553 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
from string import digits
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
T = int(input())
digits = set(list(digits))
for _ in range(T):
    S = input().rstrip()
    N = len(S)
    i = N - 1
    prev = []
    num = []
    while i >= 0:
        if not S[i] in digits:
            prev.append(S[i])
            i -= 1
        else:
            if S[i] == "9":
                up = 1
                num.append("0")
            else:
                up = 0
                num.append(str(int(S[i])+1))
            i -= 1
            while i >= 0 and S[i] in digits:
                if up:
                    if S[i] == "9":
                        num.append("0")
                    else:
                        up = 0
                        num.append(str(int(S[i]) + 1))
                else:
                    num.append(S[i])
                i -= 1
            if up:
                num.append("1")
            break
    print(S[:i+1], end="")
    print("".join(num[::-1]), end="")
    print("".join(prev[::-1]))
            
            
            
        