結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-03-20 21:04:30 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 166 ms / 2,000 ms | 
| コード長 | 693 bytes | 
| コンパイル時間 | 238 ms | 
| コンパイル使用メモリ | 82,232 KB | 
| 実行使用メモリ | 104,892 KB | 
| 最終ジャッジ日時 | 2025-03-20 21:04:34 | 
| 合計ジャッジ時間 | 1,506 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
import re
def increment(s):
    chars = list(s)
    carry = 1
    i = len(chars) - 1
    while i >= 0 and carry:
        digit = int(chars[i]) + carry
        carry = digit // 10
        chars[i] = str(digit % 10)
        i -= 1
    if carry:
        return str(carry) + ''.join(chars)
    else:
        return ''.join(chars)
T = int(input())
for _ in range(T):
    S = input().strip()
    matches = list(re.finditer(r'\d+', S))
    if not matches:
        print(S)
        continue
    last_match = matches[-1]
    start = last_match.start()
    end = last_match.end()
    num_str = last_match.group()
    new_num = increment(num_str)
    ans = S[:start] + new_num + S[end:]
    print(ans)
            
            
            
        