結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-26 14:03:18 | 
| 言語 | Nim (2.2.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 60 ms / 2,000 ms | 
| コード長 | 1,590 bytes | 
| コンパイル時間 | 2,714 ms | 
| コンパイル使用メモリ | 65,996 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-01 10:54:54 | 
| 合計ジャッジ時間 | 3,566 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport] /home/judge/data/code/Main.nim(1, 27) Warning: imported and not used: 'strutils' [UnusedImport]
ソースコード
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 printf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc putchar_unlocked(c:char){. importc:"putchar_unlocked",header: "<stdio.h>" .}
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 :
      result &= ('0'.ord + d).chr
      ch = 0
    else:
      result &= ('0'.ord + d mod 10).chr
      ch = 1
  if ch > 0: result &= ('0'.ord + ch).chr
  result.reverse()
template print(S:string) =
  for i in 0..<S.len: putchar_unlocked(S[i])
proc impl()  =
  var preAlphabets = ""
  var preNums = ""
  var isNum = false
  while true:
    let k = getchar_unlocked()
    if k.ord < 32 or k.ord > 126 :
      if isNum:
        if preAlphabets.len > 0 : print(preAlphabets)
        let added = preNums.add1()
        print(added)
      else:
        if preNums.len > 0:
          let added = preNums.add1()
          print(added)
        print(preAlphabets)
      putchar_unlocked('\n')
      return
    let kIsNum = k >= '0' and k <= '9'
    if kIsNum and not isNum:
      if preNums.len > 0:
        print(preNums)
        preNums = ""
      print(preAlphabets)
      preAlphabets = ""
    if kIsNum: preNums &= k
    else: preAlphabets &= k
    isNum = kIsNum
scan().times: impl()
            
            
            
        