読者です 読者をやめる 読者になる 読者になる

Let's write β

趣味で書いたこととか、RustとLispが好き

ICPC2005 ProblemC

Numerial Systemです。

(defun num-char-p (char)
  (when (typep char 'character)
    (<= (char-code #\0) (char-code char) (char-code #\9))))

(defun num-char-to-num (num-char)
  (-  (char-code num-char) (char-code #\0)))

(defun num-to-num-char (num)
  (code-char (+ num (char-code #\0))))

(defun mcxi-to-num (mcxi)
  (let ((mcxi-char-list (mapcar (lambda (x) (if (num-char-p x) (num-char-to-num x) x)) (coerce mcxi 'list))))
    (labels
	((%mcxi-to-num (mcxi-lst num acc)
	   (if (null mcxi-lst)
	       acc
	       (if (integerp (car mcxi-lst))
		   (%mcxi-to-num (cdr mcxi-lst) (car mcxi-lst) acc)
		   (%mcxi-to-num (cdr mcxi-lst) 1
				 (+ acc
				    (case (car mcxi-lst)
				      (#\m (* num 1000))
				      (#\c  (* num 100))
				      (#\x (* num 10))
				      (#\i (* num 1)))))))))
      (%mcxi-to-num mcxi-char-list 1 0))))

(defun %num-to-mcxi (num ch)
  (cond
    ((= 1 num) `(,ch))
    ((zerop num) nil)
    (t `(,(num-to-num-char num) ,ch))))

(defun num-to-mcxi (num)
  (coerce 
   (multiple-value-bind (m rem) (floor num 1000)
     (multiple-value-bind (c rem) (floor rem 100)
       (multiple-value-bind (x rem) (floor rem 10)
	 `(,@(%num-to-mcxi m #\m)
	     ,@(%num-to-mcxi c #\c)
	     ,@(%num-to-mcxi x #\x)
	     ,@(%num-to-mcxi rem #\i)))))
   'string))



(defun main ()
  (let ((n (read)))
    (loop for i from 1 upto n
       do
	 (format t "~A~%" (num-to-mcxi (+ (mcxi-to-num (string-downcase (string (read)))) (mcxi-to-num (string-downcase (string (read))))))))
    ))

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