結果

問題 No.539 インクリメント
ユーザー h_nosonh_noson
提出日時 2017-07-11 02:33:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 794 ms / 2,000 ms
コード長 628 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-16 16:30:45
合計ジャッジ時間 2,972 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import string

def inc(s):
    carry = len(s) > 0
    ret = ""
    for c in s[::-1]:
        if not carry:
            ret += c
        elif c == '9':
            ret += '0'
        else:
            ret += str(int(c) + 1)
            carry = False
    if carry:
        ret += '1'
    return ret[::-1]

n = int(input())
for j in range(n):
    s = input()
    l = 0
    r = -1
    digit = False
    for i,c in enumerate(s):
        if c in string.digits:
            r = i
            if not digit:
                l = i
            digit = True
        else:
            digit = False
    print(s[:l] + inc(s[l:r+1]) + s[r+1:])
0