【AtCoder ABC286A】Range Swap

関連記事

1. 問題

2. コード

リストを配列にしてから、loopでifで場合分けして集めていくことで、入れ替えたリストをつくることにしました。

(defun range-swap (P Q R S An)
  (let* ((vec (make-array (length An)
			  :element-type 'fixnum
			  :initial-contents An)))
    (loop for n from 1 to (length An)
	  if (<= P n Q)
	    collect (aref vec (1- (+ n (- R P))))
	  else if (<= R n S)
	    collect (aref vec (1- (+ n (- P R))))
	  else
	    collect (aref vec (1- n)))))

(defun main ()
  (let* ((N (read))
	  (P (read))
	  (Q (read))
	  (R (read))
	  (S (read))
	  (An (loop repeat N collect (read))))
     (loop for x in (range-swap P Q R S An)
	   do (progn (princ x)
		     (princ #\space)) )))

#-swank
(main)
Code language: Lisp (lisp)
2. コード