koukyoukoukokukikou
(defvar *qwarty-right* (coerce "yuiophjklnm" 'list)) (defvar *qwarty-left* (coerce "qwretasdfgzxcvb" 'list)) (defun count-hand-change (string) (let ((ch-list (coerce string 'list))) (labels ((%count-hand-change (ch-list before-hand acc) (if (null ch-list) acc (cond ((and (member (car ch-list) *qwarty-right*) (equal :left before-hand)) (%count-hand-change (cdr ch-list) :right (1+ acc))) ((and (member (car ch-list) *qwarty-left*) (equal :right before-hand)) (%count-hand-change (cdr ch-list) :left (1+ acc))) (t (%count-hand-change (cdr ch-list) before-hand acc)))))) (if (member (car ch-list) *qwarty-left*) (%count-hand-change (cdr ch-list) :left 0) (%count-hand-change (cdr ch-list) :right 0))))) (defun main () (loop for line = (read-line) until (string= "#" line) do (format t "~A~%" (count-hand-change line))))
再帰で。