我曾尝试用不同的编程语言进行2020年的google KickStart竞赛,但我的通用lisp(sbcl)和clojure代码在google测试中失败,但它们都在我的本地机器上正常工作,知道我做错了什么吗?
工作的python代码如下所示:
def short_path(n,k,s):
return min((k + n),(2*k - 2*s + n))
for i in range (1,int(input())+1):
print("Case #{}: {}".format(i,short_path(*[int(z) for z in input().split()])))
Lisp(sbcl)版本:
(defun short_path (n k s)
(let (x y)
(setf x (+ n k))
(setf y (+ (- (* k 2) (* 2 s)) n))
(if (< x y) x y)))
(defun main ()
(loop for i from 1 to (read)
do (format t "Case #~a: ~a~%" i (short_path (read) (read) (read)))))
Clojure版本:
(defn short_path [n k s]
(min (+ n k) (+ n (- (* 2 k) (* 2 s)))))
(defn main []
(dotimes [i (read)] (println (str "Case #" (+ i 1) ": " (short_path (read) (read) (read))))))
编辑: 对于测试,我们应使用:
cat Sample.in | python retype.py
cat Sample.in | sbcl --script retype.lisp
cat Sample.in | clj retype.clj
Sample.in:
6
10 5 2
10 7 6
10 5 5
10 6 5
3 2 1
100 40 30
我不知道你的代码的目的是什么,但是
let
的使用在我看来很奇怪。最好尝试:查看Google Kick Start platform notes for Clojure,测试运行程序希望运行脚本而不是
-main
函数。我还没有注册Google Kick Start,但这应该可以:相关问题 更多 >
编程相关推荐