結果
| 問題 |
No.113 宝探し
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-10-07 23:01:22 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 5,000 ms |
| コード長 | 1,091 bytes |
| コンパイル時間 | 269 ms |
| コンパイル使用メモリ | 37,296 KB |
| 実行使用メモリ | 32,152 KB |
| 最終ジャッジ日時 | 2024-10-07 23:01:24 |
| 合計ジャッジ時間 | 1,373 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 07 OCT 2024 11:01:22 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.114
ソースコード
; xy座標の初期値を x = 0, y = 0 として1文字ずつ処理する
; x <- x + 1 ('E')
; x <- x - 1 ('W')
; y <- y + 1 ('N')
; y <- y - 1 ('S')
; 最後に sqrt(x * x + y * y) を出力する
(defun main ()
(let* ((s (read-line))
(x 0)
(y 0))
(loop for c across s
; case はエラーを発生させたくない場合やデフォルトの動作を設定したい場合に使う
; ccase は必ずマッチがあるべきだが安全にチェックを行いたい場合に使う
; ecase はマッチするキーが必ずあるべき状況で使う
do (ecase c
(#\N (incf y))
(#\E (incf x))
(#\W (decf x))
(#\S (decf y))))
; sqrt 関数は平方根を求める
; 手元の sbcl では
; (sqrt 36) => 6.0
; (sqrt 123) => 11.090536
; (sqrt -2) => #C(0.0 1.4142135)
; (sqrt #c(0 3)) #C(1.2247449 1.2247449)
; となった
(princ (sqrt (+ (* x x) (* y y))))
(terpri)))
(main)
Common Lisp