結果

問題 No.279 木の数え上げ
ユーザー yusakayusaka
提出日時 2015-09-22 04:10:40
言語 Scheme
(Gauche-0.9.14)
結果
RE  
実行時間 -
コード長 1,050 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 30,076 KB
最終ジャッジ日時 2023-09-26 14:20:33
合計ジャッジ時間 3,878 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env gosh
(define (main args)
  (let ((input (read-line)))
    (display (count-tree input))
    (newline)))

(define (count-tree str)
  (let ((char-list (string->list str))
        (count-char-lambdas (list (count-char #\t)
                                  (count-char #\r)
                                  (div2 (count-char #\e)))))
    (define (apply-lambdas lst arg)
      (if (equal? '() lst)
          lst
          (cons ((car lst) arg) (apply-lambdas (cdr lst) arg))))
    (minimum (apply-lambdas count-char-lambdas char-list))))

(define (minimum lst)
  (define (iter lst holder)
    (if (null? lst)
        holder
        (if (< holder (car lst))
            (iter (cdr lst) holder)
            (iter (cdr lst) (car lst)))))
  (iter (cdr lst) (car lst)))

(define (div2 f)
  (lambda (x)
    (/ (f x) 2)))

(define (count-char char)
  (lambda (x)
    (define (iter x i)
      (if (equal? x '())
          i
          (if (equal? (car x) char)
              (iter (cdr x) (+ i 1))
              (iter (cdr x) i))))
    (iter x 0)))
0