結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 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 redef increment(s):chars = list(s)carry = 1i = len(chars) - 1while i >= 0 and carry:digit = int(chars[i]) + carrycarry = digit // 10chars[i] = str(digit % 10)i -= 1if 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)continuelast_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)