比赛 |
20100914 |
评测结果 |
AAAWAWAAAA |
题目名称 |
算24点 |
最终得分 |
80 |
用户昵称 |
donny |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-09-14 20:12:05 |
显示代码纯文本
program point24(input,output);
var
a:array[1..4]of integer;
b:array[1..4]of boolean;
c:array[0..4]of integer;
d:array[1..4]of char;
i,j,k,l:integer;
procedure search(x,y:integer);
var
i,j,k:integer;
begin
if x=4 then
begin
if y=24 then
begin
k:=c[1];
for i:=1 to 3 do
begin
case d[i] of
'+': j:=k+c[i+1];
'-': j:=k-c[i+1];
'*': j:=k*c[i+1];
'/': j:=k div c[i+1];
end;
if k>c[i+1] then
writeln(k,d[i],c[i+1],'=',j)
else
writeln(c[i+1],d[i],k,'=',j);
k:=j;
end;
close(input);
close(output);
halt;
end;
end
else
begin
for i:=1 to 4 do
if b[i] then
begin
b[i]:=false;
inc(c[0]);
c[c[0]]:=a[i];
if x=0 then search(x+1,a[i])
else
begin
d[x]:='+';
search(x+1,y+a[i]);
if y-a[i]>0 then
begin
d[x]:='-';
search(x+1,y-a[i]);
end;
d[x]:='*';
search(x+1,y*a[i]);
if y mod a[i]=0 then
begin
d[x]:='/';
search(x+1,y div a[i]);
end;
end;
b[i]:=true;
dec(c[0]);
end;
end;
end;
begin
assign(input,'point24.in');
reset(input);
assign(output,'point24.out');
rewrite(output);
for i:=1 to 4 do
read(a[i]);
for i:=1 to 4 do
b[i]:=true;
search(0,0);
writeln('No answer!');
close(input);
close(output);
end.