09/06/09 13:32:07
>>112 6、
% Prolog
t112_6(X) :- get_integer(N),t112_6(N,[N],X).
t112_6(N,L,N) :- count(N,L,3).
t112_6(N,L,X) :- get_integer(M),t112_6(M,[M|L],X).
count(A,[],0).
count(A,[A|R],X) :- count(A,R,Y),X is Y+1.
count(A,[_|R],X) :- count(A,R,X).
get_integer(N) :- repeat,write('整数(0-9).改行 ? '),read(N),N>=0,N=<9,!.