【AtCoder ABC397B】Ticket Gate Log(Common Lisp)

関連記事

1. 問題

2. 回答

前の文字と同じ文字だと +1 していって、あとは 最初と最後の文字を確認します。
1文字は o なら +1、最終文字が i なら+1、します。

(defun restore-io (str)
  (let* ((lst (loop for ch across str
		    collect ch)))
    (loop for (a b) on lst
	  for i from 0
	  with result = 0
	  when (and (= i 0) (eql a #\o))
	    do (incf result)
	  when (eql a b)
	    do (incf result)
	  when (and (null b) (eql a #\i))
	    do (incf result)
	  finally (return result))))

(defun main ()
  (princ (restore-io (read-line))))

#-swank
(main)
Code language: Lisp (lisp)
2. 回答