fork download
  1. (defpackage "ODAI-PT15-467" (:use "COMMON-LISP"))
  2. (in-package "ODAI-PT15-467")
  3.  
  4. (defun groups (seq &key (test #'eql) (key #'identity))
  5. (loop for start = 0 then end
  6. for end = (position-if (lambda (x)
  7. (not (funcall test
  8. (funcall key (elt seq start))
  9. x)))
  10. seq
  11. :start start
  12. :key key)
  13. collect (subseq seq start end)
  14. while end))
  15.  
  16. (defun odai-pt15-467 (s)
  17. (apply #'concatenate 'string
  18. (mapcar (lambda (x)
  19. (format nil "~A~A"
  20. (elt x 0)
  21. (if (> (length x) 1) (length x) "")))
  22. (groups s))))
  23.  
  24. (dolist (s '("あいうえお"
  25. "ああいいうう"
  26. "あいうあいう"
  27. "ああああ"
  28. "🐤🐤🐤🐤"))
  29. (write-line (odai-pt15-467 s)))
  30.  
Success #stdin #stdout 0.01s 25588KB
stdin
Standard input is empty
stdout
あいうえお
あ2い2う2
あいうあいう
あ4
🐤4