結果

問題 No.539 インクリメント
ユーザー rpy3cpprpy3cpp
提出日時 2017-06-30 23:29:53
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,341 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 76,700 KB
実行使用メモリ 105,720 KB
最終ジャッジ日時 2024-04-15 07:08:39
合計ジャッジ時間 4,469 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,644 KB
testcase_01 AC 82 ms
76,816 KB
testcase_02 AC 1,341 ms
105,720 KB
testcase_03 AC 1,195 ms
102,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(s):
    idx = len(s)
    flag = False
    last = 0
    for c in s[::-1]:
        idx -= 1
        if '0' <= c and c <= '9':
            if not flag:
                flag = True
                last = idx + 1
        elif flag:
            first = idx + 1
            incremented = s[:first] + increment(s[first:last]) + s[last:]
            return incremented
    if flag:
        first = 0
        incremented = s[:first] + increment(s[first:last]) + s[last:]
        return incremented
    return s

def increment(s):
    ints = int(s)
    n = len(s)
    numn = len(str(ints))
    incremented = str(ints + 1)
    if numn == len(incremented):
        return '0' * (n - numn) + incremented
    if s[0] == '0':
        return '0' * (n - numn - 1) + incremented
    return incremented

    

n = int(raw_input())
for i in range(n):
    s = raw_input().rstrip()
    print(solve(s))
0