結果

問題 No.539 インクリメント
ユーザー hedwig100hedwig100
提出日時 2020-05-25 16:24:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 14,068 KB
最終ジャッジ日時 2024-04-21 03:46:16
合計ジャッジ時間 1,157 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,624 KB
testcase_01 AC 63 ms
14,068 KB
testcase_02 AC 59 ms
11,652 KB
testcase_03 AC 196 ms
12,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def solve():
    S = list(input())
    first = False
    for i in range(len(S) - 1,-1,-1):
        if 0 <= ord(S[i]) - 48 < 10:
            if 0 <= ord(S[i]) - 48 < 9:
                S[i] = chr(ord(S[i]) + 1)
                first = False
                break
            else:
                S[i] = '0' 
                first = True
        else:
            if first:
                S = S[:i + 1] + ['1'] + S[i + 1:]
                first = False
                break
    if first:
        S = ['1'] + S
    print(''.join(S))


T = int(input())
for _ in range(T):
    solve()
0