結果

問題 No.539 インクリメント
ユーザー c-yanc-yan
提出日時 2020-12-31 00:20:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,169 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,468 KB
最終ジャッジ日時 2024-04-17 00:50:40
合計ジャッジ時間 3,273 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 32 ms
11,392 KB
testcase_02 AC 1,169 ms
17,360 KB
testcase_03 AC 1,017 ms
17,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def increment(S):
    carry = 1
    t = []
    for c in reversed(S):
        x = int(c) + carry
        if x == 10:
            t.append('0')
            carry = 1
        else:
            t.append(str(x))
            carry = 0
    if carry == 1:
        t.append('1')
    t = ''.join(reversed(t))
    if S[0] != '0':
        return t
    return S[:len(S)-len(t)] + t


def f(S):
    n = len(S)
    l, r = 0, 0
    for i in range(n):
        if r == 0 and S[n - 1 - i] in '0123456789':
            r = n - i
        elif r != 0 and S[n - 1 - i] not in '0123456789':
            l = n - i
            break
    if r == 0:
        return S
    return S[:l] + increment(S[l:r]) + S[r:]


T = int(input())
for _ in range(T):
    S = input()
    print(f(S))
0