結果

問題 No.539 インクリメント
ユーザー mitsuomitsuo
提出日時 2018-08-22 11:03:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,159 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 15,484 KB
最終ジャッジ日時 2023-08-25 02:13:42
合計ジャッジ時間 1,748 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,272 KB
testcase_01 AC 68 ms
15,484 KB
testcase_02 AC 66 ms
14,468 KB
testcase_03 AC 252 ms
14,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import re

def partsolve2(l):
    l = list(l)
    addone = False
    started = False
    n = 0
    for i, c in enumerate(l[::-1]):
        n = i
        if 0x30 <= ord(c) <= 0x38:
            l[len(l) - i - 1] = chr(ord(c) + 1)
            addone = False
            break
        elif ord(c) == 0x39:
            l[len(l) - i - 1] = "0"
            addone = True
            started = True
        else:
            if addone:
                l.insert(len(l) - i, "1")
                addone = False
            if started:
                break

    if addone:
        l.insert(len(l) - n - 1, "1")

    return "".join(l)

def partsolve(l):
    match_list = re.findall("[0-9]+", l)
    if match_list:
        last = match_list[-1]
        size = len(last)
        replace = ("{:0" + str(size) + "}").format(int(last) + 1)
        data = re.sub(last[::-1], replace[::-1], l[::-1], count=1)
        return data[::-1]
    else:
        return l

def solve(N, lines):
    ret = []
    for l in lines:
        ret.append(partsolve2(l))
    return ret

if __name__ == "__main__":
    N = int(input())
    [print(s) for s in solve(N, [input() for _ in range(N)])]
0