Last active
April 27, 2018 16:14
-
-
Save alandipert/5cf98cba9b9709976a423e598097dac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Solution to https://uva.onlinejudge.org/external/112/p11220.pdf | |
(defun split-string (string &optional (sep-char #\space)) | |
(loop for i = 0 then (1+ j) | |
for j = (position sep-char string :start i) | |
collect (subseq string i j) | |
while j)) | |
(defun decode-line (str) | |
(loop for word in (split-string str) | |
with index = 0 | |
if (> (length word) index) | |
collect (elt word index) into chars | |
and do (incf index) | |
finally (return (coerce chars 'string)))) | |
(defun decode-file (file) | |
(with-open-file (stream file) | |
;; Read and discard # of cases at top of file | |
(read-line stream nil nil) | |
(loop for line = (read-line stream nil nil) | |
for case-sep = "" then (format nil "~%") | |
with case-num = 0 | |
while line | |
do (if (zerop (length line)) | |
(format t "~ACase #~A~%" case-sep (incf case-num)) | |
(format t "~A~%" (decode-line line)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment