; 24時間以上寝続けないので ; (a = 起きた時(分)) >= (b = 寝た時(分)) ; なら a - b それ以外なら (24 * 60 + b) - a ; 記録し足す ; 時刻 HH:MM の 00:00 からの経過分を求める関数 (defun g (hh mm) (+ (* hh 60) mm)) ; "HH1:MM1 HH2:MM2" 形式で与えられた睡眠時間HH1:MM1と起床時間HH2:MM2を経過分数に直す関数 (defun f (s) (let* ( ; position item sequence &key from-end test test-not start end key => position ; position 関数は sequence 中で item が存在する場所を0スタートで返す ; from-end の値が true のとき後ろから検索する ; sp 空白位置 (sp (position #\space s)) ; c1 寝る時間のコロンの位置 (c1 (position #\: s)) ; c2 起きる時間のコロンの位置 (c2 (position #\: s :from-end t)) ; read-from-string string &optional eof-error-p eof-value &key start end preserve-whitespace => object, position ; read-from-string 関数は文字列を引数として受け取り ; start から end までの部分Lispオブジェクトを得ることができる (デフォルトはstart=0, end=nilで全文字列) ; eof-error-p を t, eof-value を nil にすることで返り値として eof を返させない ; 余計な空白は無いと考えるので preserve-whitespace は false (つまりデフォルト)とする (bedtime (g (read-from-string s t nil :end c1) (read-from-string s t nil :start (1+ c1) :end sp))) (wake-up-time (g (read-from-string s t nil :start (1+ sp) :end c2) (read-from-string s t nil :start (1+ c2)))) ) (if (> bedtime wake-up-time) (- (+ 1440 wake-up-time) bedtime) (- wake-up-time bedtime)))) (defun main () (let* ((n (read)) (ans 0)) (dotimes (_ n) (incf ans (f (read-line)))) (princ ans) (terpri))) (main)