結果

問題 No.539 インクリメント
ユーザー sue_charosue_charo
提出日時 2017-06-30 23:21:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,859 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 24,940 KB
最終ジャッジ日時 2024-04-15 07:04:40
合計ジャッジ時間 4,064 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
18,588 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    T = II()
    test = [str(input()) for __ in range(T)]
    return T, test


def RepresentsInt(s):
    try:
        int(s)
        return True
    except ValueError:
        return False


def solve(T, test):
    ans = []
    for t in test:
        l_ind = []
        head_ind = None
        for ind, char in enumerate(t):
            if RepresentsInt(char):
                if head_ind is None:
                    head_ind = ind
                else:
                    continue
            else:
                if head_ind is None:
                    continue
                else:
                    l_ind.append((head_ind, ind - 1))
                    head_ind = None
        else:
            if head_ind is not None:
                l_ind.append((head_ind, len(t) - 1))

        if len(l_ind) == 0:
            ans.append(t)
        else:
            front_ind, back_ind = l_ind[-1]
            front_str = "".join(t[:front_ind])
            num_str = "".join(t[front_ind:back_ind + 1])
            back_str = "".join(t[back_ind + 1:])

            len_num = len(num_str)
            num_leveled = str(int(num_str) + 1)
            if len_num > len(num_leveled):
                num_leveled = num_leveled.zfill(len_num)

            all_joined = front_str + num_leveled + back_str
            ans.append(all_joined)

    return ans


def main():
    params = read()
    ans = solve(*params)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()
0