結果

問題 No.539 インクリメント
ユーザー H3PO4H3PO4
提出日時 2020-09-16 21:49:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 615 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 11,156 KB
最終ジャッジ日時 2023-09-04 03:59:53
合計ジャッジ時間 1,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
9,068 KB
testcase_01 AC 133 ms
9,424 KB
testcase_02 AC 227 ms
11,024 KB
testcase_03 AC 377 ms
11,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import re

T = int(input())
regex = re.compile(r'([0-9]+)([^0-9]*$)')

d = {str(x): str((x + 1) % 10) for x in range(10)}


def func(m):
    num_str = m.group(1)
    new_num_list = list(num_str)
    flag = True
    for i, s in enumerate(num_str[::-1], 1):
        new_num_list[-i] = d[new_num_list[-i]]
        # 繰り上がり判定
        if s != '9':
            flag = False
            break
    new_num_str = ''.join(map(str, new_num_list))
    if flag:
        new_num_str = '1' + new_num_str
    return new_num_str.zfill(len(num_str)) + m.group(2)


for _ in range(T):
    print(regex.sub(func, input()))
0