fork download
  1. (defun groups (seq &key (test #'eql) (key #'identity))
  2. (loop for start = 0 then end
  3. for end = (position-if (lambda (x)
  4. (not (funcall test
  5. (funcall key (elt seq start))
  6. x)))
  7. seq
  8. :start start
  9. :key key)
  10. collect (subseq seq start end)
  11. while end))
  12.  
  13. (defun string-alphanumericp (string)
  14. (check-type string string)
  15. (every #'alphanumericp string))
  16.  
  17. (defun escape-format-string (string)
  18. (apply #'concatenate 'string
  19. (loop for c across string
  20. if (char= c #\~)
  21. collect "~~"
  22. else
  23. collect (string c))))
  24.  
  25. (defun odai-pt14-651 (string)
  26. (let* ((segments (groups string :key #'alphanumericp))
  27. (fmt-string (format nil "~{~A~}~%"
  28. (mapcar (lambda (s)
  29. (if (string-alphanumericp s)
  30. "~A"
  31. (escape-format-string s)))
  32. segments)))
  33. (words (remove-if (complement #'string-alphanumericp) segments)))
  34. (apply #'format t fmt-string (reverse words))))
  35.  
  36. (loop while (listen)
  37. do (odai-pt14-651 (read-line)))
  38.  
Success #stdin #stdout 0s 203840KB
stdin
Hello, World!
世界よ、こんにちは。
お題: Hello, World!が入力されるのでHelloとWorldを入れ替えて表示せよ
A!B"C#D$E%F&G'H(I)J*K+L,M-N.O/P:Q;R<S=T>U?V@W[X\Y]Z^0_1`2{3|4}5~
stdout
World, Hello!
こんにちは、世界よ。
が入力されるのでHelloとWorldを入れ替えて表示せよ: World, Hello!お題
5!4"3#2$1%0&Z'Y(X)W*V+U,T-S.R/Q:P;O<N=M>L?K@J[I\H]G^F_E`D{C|B}A~