0

我在序言中尝试了这个回文程序,逻辑有效,但写操作不起作用。那么代码中的问题是什么?

佩林(列表 1):- findrev(列表 1,[],列表 2),比较(列表 1,列表 2)。

findrev([],List1,List1).

findrev([X|Tail],List1,List2):-
    findrev(Tail,[X|List1],List2).

compare([],[]):-
    write("\nList is Palindrome").

compare([X|List1],[X|List2]):-
    compare(List1,List2).

compare([X|List1],[Y|List2]):-
    write("\nList is not Palindrome").
4

1 回答 1

1

这个对我有用。我使用 SWI 序言。并尝试将“替换为”。因为"Something"它会将其打印为数字列表,而不是字符串。

于 2011-09-13T18:18:38.050 回答