0

从列表 pl 中读取多项式(输入格式见下文)并将其作为排序列表返回。

示例:(ReadPolynomial2 '(99 0 17 200 3 150 8 200 0 0))应该返回((99 0) (3 150) (25 200))

4

1 回答 1

0

我不知道你是否还需要它,但这是一个可能的解决方案:

(defun ReadPolynomial2 (lst)
  (let ((even-positions (loop for p in (cdr lst) by #'cddr collect p)))
    (loop for p in (remove-duplicates even-positions)
          collect (list (loop for x on lst by #'cddr
                              when (= p (second x))
                              sum (first x)) p))))
于 2013-02-10T02:44:42.397 回答