結果

問題 No.539 インクリメント
ユーザー むらためむらため
提出日時 2019-01-26 13:26:56
言語 Nim
(2.0.2)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 2,961 ms
コンパイル使用メモリ 69,924 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2023-09-14 02:55:48
合計ジャッジ時間 4,445 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 108 ms
9,984 KB
testcase_02 AC 32 ms
7,644 KB
testcase_03 AC 34 ms
7,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,algorithm,strutils
template times*(n:int,body) = (for _ in 0..<n: body)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

proc parse(): seq[tuple[str:string,isNum:bool]] =
  result = @[]
  var current = ""
  var isNum = false
  while true:
    let k = getchar_unlocked()
    if k.ord < 32 or k.ord > 126 :
      result &= (current,isNum)
      return
    let kIsNum = k >= '0' and k <= '9'
    if isNum xor kIsNum and current != "":
      result &= (current,isNum)
      current = ""
    current &= k
    isNum = kIsNum

proc add1(S:string):string =
  result = ""
  var ch = 1
  for i in (S.len-1).countdown(0):
    let c = S[i].ord - '0'.ord
    let d = c + ch
    if d < 10 :
      ch = 0
      result &= ('0'.ord + d).chr
    else:
      ch = 1
      result &= ('0'.ord + d mod 10).chr
  if ch > 0:
    result &= ('0'.ord + ch).chr
  result.reverse()
scan().times:
  var P = parse()
  for i in (P.len()-1).countdown(0):
    if not P[i].isNum : continue
    P[i].str = P[i].str.add1()
    break
  echo P.mapIt(it.str).join("")
0