Let's write β

プログラミング中にできたことか、思ったこととか

JAG2010ProblemB

Moonlight Farm

(defstruct seed 
  name p a b c d e f s m)

(defmethod calc-max-time ((s seed))
  (+ (seed-a s) (seed-b s) (seed-c s) (seed-d s) (seed-e s)
     (loop for i from 1 upto (1- (seed-m s))
	  sum (+ (seed-d s) (seed-e s)))))

(defmethod calc-max-price ((s seed))
  (* (seed-s s) (seed-f s) (seed-m s)))

(defmethod calc-income-efficiency ((s seed))
  (/ (- (calc-max-price s) (seed-p s))
     (calc-max-time s)))

(defun read-seed ()
  (make-seed
   :name (string-downcase (string (read)))
   :p (read)
   :a (read)
   :b (read)
   :c (read)
   :d (read)
   :e (read)
   :f (read)
   :s (read)
   :m (read)))

(defun main ()
  (loop for n = (read)
       until (zerop n)
       do
       (let ((seeds (loop for i from 1 upto n
		       collect (read-seed))))
	 (format t "~{~A~^~%~}~%#~%"
		 (loop for seed in 
		      (sort 
		       seeds
		       (lambda (a b)
			 (let ((ef1 (calc-income-efficiency a))
			       (ef2 (calc-income-efficiency b)))
			   (cond ((= ef1 ef2)
				  (< (char-code (aref (seed-name a) 0))
				     (char-code (aref (seed-name b) 0))))
				 (t 
				  (> ef1 ef2))))))
		      collect (seed-name seed))))))

データのreadと、ソートの基準の書き方が面倒でした。

僕が働いているAzit.incでは一緒に働けるエンジニアを募集しています!
採用情報 — 株式会社アジット|Azit Inc.