結果

問題 No.539 インクリメント
ユーザー naoya_tnaoya_t
提出日時 2017-06-30 23:02:46
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 619 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 14,136 KB
最終ジャッジ日時 2024-04-15 06:55:46
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import re

def solve(s):
  sR = s[::-1]
  lastspan = None
  for mo in re.finditer(r'\d+', sR):
    lastspan=mo.span()
    break
  if lastspan is None:
    return s
  else:
    L = len(s)
    b, e = lastspan
    b, e = L-e, L-b 
    nu = s[b:e]
    mo = re.match(r'^(0*)(([1-9][0-9]*)?)$', nu)
    pad, body = mo.group(1), mo.group(2)
    if body=='':
      pad = pad[1:]
      body = '0'
    plus = str(int(body)+1)
    if len(plus) > len(body):
      if len(pad) > 0:
        pad = pad[1:]
    return s[:b] + pad + plus + s[e:]

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