結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー むらためむらため
提出日時 2017-08-15 21:01:51
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 828 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 73,520 KB
最終ジャッジ日時 2024-04-27 02:29:07
合計ジャッジ時間 1,176 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(16, 6) Error: type mismatch
Expression: c_fgets(buf, 200002, stdin)
  [1] buf: array[0..200001, char]
  [2] 200002: int
  [3] stdin: File

Expected one of (first mismatch at [position]):
[1] proc c_fgets(c`gensym3: cstring; n`gensym3: int; file`gensym3: File): void

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,macros
import sets,tables,hashes
template get*():string = stdin.readLine() #.strip()

proc coundDuplicate[T](keys:openArray[T]): seq[tuple[key:T,val:int]] =
  var ct = initCountTable[T](nextPowerOfTwo(keys.len * 3 div 2 + 4))
  for k in items(keys): ct[k] = 1 + (if k in ct : ct[k] else: 0)
  return toSeq(ct.pairs)

template fgets(f:File,buf:untyped,size:int):void =
  proc c_fgets(c: cstring, n: int, file: File): void {.importc: "fgets", header: "<stdio.h>", tags: [ReadIOEffect].}
  var buf: array[size, char]
  c_fgets(buf,sizeof(buf),f)

let N = get().parseInt
stdin.fgets(buf,100000 * 2 + 2)
echo buf.coundDuplicate()
  .filterIt('0' <= it.key and it.key <= '9')
  .sorted((x,y) => (if x.val != y.val : x.val - y.val else: x.key.ord - y.key.ord),Descending)[0].key
0