結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  naoya_t | 
| 提出日時 | 2017-06-30 23:22:42 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 811 ms / 2,000 ms | 
| コード長 | 829 bytes | 
| コンパイル時間 | 80 ms | 
| コンパイル使用メモリ | 7,040 KB | 
| 実行使用メモリ | 8,372 KB | 
| 最終ジャッジ日時 | 2024-10-04 21:27:48 | 
| 合計ジャッジ時間 | 2,463 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
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)
            
            
            
        