Skip to content

Instantly share code, notes, and snippets.

@meki
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meki/8783957 to your computer and use it in GitHub Desktop.
Save meki/8783957 to your computer and use it in GitHub Desktop.
AOJ_0001_Common Lisp
;; 標準入力から n 回受け取ってリストに追加
(defun input (lst n)
(cond
((eq (length lst) n)
lst
)
(t
(input (append lst (list (read)) ) n )
)
)
)
;; リストの先頭 n 要素の部分配列を作成
(defun gettop (lst n)
(if (or (= n 0) (null lst))
nil
(cons (car lst)
(gettop (cdr lst) (- n 1))
)
)
)
(mapcar #'(lambda (x) (format t "~A~%" x)) ; リストの要素を改行区切りで出力する
(gettop
(sort (input () 10) #'>) ; 標準入力からリストを作り降順ソートする
3 ; 先頭3つのリストを作成
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment