結果

問題 No.539 インクリメント
コンテスト
ユーザー naoya_t
提出日時 2017-06-30 23:02:46
言語 PyPy2
(7.3.20)
結果
AC  
実行時間 851 ms / 2,000 ms
コード長 619 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 144 ms
コンパイル使用メモリ 77,220 KB
最終ジャッジ日時 2025-12-04 00:20:49
ジャッジサーバーID
(参考情報)
judge3 / judge5
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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