結果

問題 No.539 インクリメント
ユーザー naoya_tnaoya_t
提出日時 2017-06-30 23:22:42
言語 Python2
(2.7.18)
結果
AC  
実行時間 801 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 8,500 KB
最終ジャッジ日時 2024-04-15 07:05:30
合計ジャッジ時間 2,257 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def solve(s):
  L = len(s)
  sR = s[::-1]
  b=-1
  e=-1
  for i in xrange(L):
    if sR[i] < '0' or '9' < sR[i]: continue
    b=e=i
    while e<L:
      if '0' <= sR[e] <= '9':
        e += 1
        continue
      break
    break
  if b==-1:
    return s
  else:
    b, e = L-e, L-b 
    nu = s[b:e]
    pad=0
    for i in xrange(b,e):
      if s[i]=='0': pad += 1
      else: break
    if b+pad == e:
      pad -= 1

    plus=[]
    body = s[b+pad:e]
    u=1
    for c in body[::-1]:
      cu = ord(c)+u
      if cu == 58:
        u, ch = 1, '0'
      else:
        u, ch = 0, chr(cu)
      plus.append(ch)
    if u==1:
      plus.append('1')
      if pad > 0:
        pad -= 1
    return s[:b] + ('0'*pad) + ''.join(plus[::-1]) + s[e:]

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