pascal算24点(用穷举)

来源:百度知道 编辑:UC知道 时间:2024/06/08 08:25:43
麻烦了.

const as:array[1..24] of integer=(1234,1243,1324,1342,1423,1432,2134,2143,2314,2341,2413,2431,3124,3142,3214,3241,3412,3421,4123,4132,4213,4231,4312,4321);{穷举所有可能的排列}
var a,b,c,d,i,j,k,l,t,t1,t2,o:integer;
{t存放每次的结果结果,o存放最终个数}
e:array[1..4] of 1..13; u:0..1;
procedure js(x,y,z:integer); {四种运算}
begin
if z=1 then t:=x+y
else if z=2 then if x<y then u:0 else t:=x-y {u判断是否有可能}
{不交换,避免重复,方便输出}
else if z=3 then t:=x*y
else if x mod y=0 then t:=x div y else u:=0;
end;
procedure output(p:integer); {输出符号}
begin
if p=1 then write(‘+’)
else if p=2 then write('-')
else if p=3 then write('*')
else write('/');
end;
begin
readln(a,b,c,d); o:=0;
for i:=1 to 24 do
begin
e[1]:=as[i] div 1000;
e[2]:=(as[i]-e[1]*1000) div 100;
e[3]:=(as[i] mod 100) div 10;
e[4]:=as[i] mod 10; {读入四种可能}
for j:=1 to 4 do if e[j]=1 then e[j]:=a;