算24点怎么编
展开全部
这位同志是说编程......
给出24点的PASCAL标程,如果是其他语言的稍微改进一下啦:
type pdyj1=array[1..4] of longint;
var a:pdyj1;
b:array[1..3,1..4] of longint;
i,j,k,l,w,y,x:longint;
label 1;
procedure pp;
begin
for i:=1 to 3 do
begin
for j:=1 to 4 do
if j=2 then begin
case b[i,j] of
1:write('+');
2:write('-');
3:write('*');
4:write('/');
end;
end
else if j=4 then write('=',b[i,j])
else write(b[i,j]);
writeln;
end;
end;
procedure dd(k:longint;a:pdyj1);
var i,j,l,m,t,r,o,x,y,e:longint;
c:pdyj1;
begin
m:=k+1;
if (k=3) and (a[1]=24) then begin
pp;
halt;
end
else begin
for i:=1 to 3-k do
begin
j:=i+1;
x:=a[i];y:=a[j];
b[m,1]:=x;b[m,3]:=y;b[m,4]:=-1;
t:=0;
for l:=1 to i-1 do begin
inc(t);
c[t]:=a[l];
end;
inc(t);o:=t;
for l:=i+2 to 4-k do begin t:=t+1;c[t]:=a[l];end;
for l:=1 to 4 do
begin
case l of
1:b[m,4]:=x+y;
2:b[m,4]:=x-y;
3:b[m,4]:=x*y;
4:if (y<>0) and (x mod y=0)then b[m,4]:=x div y;
end;
if b[m,4]>=0 then
begin
c[o]:=b[m,4];
b[m,2]:=l;
dd(m,c);
end;
end;
end;
end;
end;
begin
assign(input,'point.in');
reset(input);
assign(output,'point.out');
rewrite(output);
for i:=1 to 4 do read(a[i]);
j:=0;
dd(j,a);
writeln('No answer!');
close(input);
close(output);
end.
给出24点的PASCAL标程,如果是其他语言的稍微改进一下啦:
type pdyj1=array[1..4] of longint;
var a:pdyj1;
b:array[1..3,1..4] of longint;
i,j,k,l,w,y,x:longint;
label 1;
procedure pp;
begin
for i:=1 to 3 do
begin
for j:=1 to 4 do
if j=2 then begin
case b[i,j] of
1:write('+');
2:write('-');
3:write('*');
4:write('/');
end;
end
else if j=4 then write('=',b[i,j])
else write(b[i,j]);
writeln;
end;
end;
procedure dd(k:longint;a:pdyj1);
var i,j,l,m,t,r,o,x,y,e:longint;
c:pdyj1;
begin
m:=k+1;
if (k=3) and (a[1]=24) then begin
pp;
halt;
end
else begin
for i:=1 to 3-k do
begin
j:=i+1;
x:=a[i];y:=a[j];
b[m,1]:=x;b[m,3]:=y;b[m,4]:=-1;
t:=0;
for l:=1 to i-1 do begin
inc(t);
c[t]:=a[l];
end;
inc(t);o:=t;
for l:=i+2 to 4-k do begin t:=t+1;c[t]:=a[l];end;
for l:=1 to 4 do
begin
case l of
1:b[m,4]:=x+y;
2:b[m,4]:=x-y;
3:b[m,4]:=x*y;
4:if (y<>0) and (x mod y=0)then b[m,4]:=x div y;
end;
if b[m,4]>=0 then
begin
c[o]:=b[m,4];
b[m,2]:=l;
dd(m,c);
end;
end;
end;
end;
end;
begin
assign(input,'point.in');
reset(input);
assign(output,'point.out');
rewrite(output);
for i:=1 to 4 do read(a[i]);
j:=0;
dd(j,a);
writeln('No answer!');
close(input);
close(output);
end.
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
5 5 5 5;6 6 6 6;5 5 1 1;5 5 2 2;5 5 3 3;5 5 4 4;5 5 6 6;5 5 7 7;5 5 8 8;5 5 9 9;5 5 10 10;6 6 6 2
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1333,1679,2499,2569,4558,5679,2557,4457,3789,3333,3478
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询