Keitai Message
これもまぁ素直な実装ね。再帰でやるのがたのしい
(defvar *button-table* '((#\. #\, #\! #\? #\Space) (#\a #\b #\c) (#\d #\e #\f) (#\g #\h #\i) (#\j #\k #\l) (#\m #\m #\o) (#\p #\q #\r #\s) (#\t #\u #\v) (#\w #\x #\y #\z))) (defun look-up-table (btn cnt) (cond ((null btn) nil) ((= btn 9) (nth (mod (1- cnt) 4) (nth (1- btn) *button-table*))) ((= btn 1) (nth (mod (1- cnt) 5) (nth (1- btn) *button-table*))) (t (nth (mod (1- cnt) 3) (nth (1- btn) *button-table*))))) (defun simu-keitai (btn-str) (let ((btn-list (mapcar (lambda (x) (- (char-code x) (char-code #\0))) (coerce btn-str 'list)))) (labels ((%simu-keitai (btn-list prev-btn cnt acc) (if (null btn-list) acc (if (equal (car btn-list) 0) (%simu-keitai (cdr btn-list) nil 0 (cons (look-up-table prev-btn cnt) acc)) (%simu-keitai (cdr btn-list) (car btn-list) (1+ cnt) acc) )))) (coerce (remove-if #'null (nreverse (%simu-keitai btn-list nil 0 ()))) 'string)))) (defun main () (let ((n (read))) (loop for i from 1 upto n do (format t "~A~%" (simu-keitai (read-line))))))