比赛 |
练习赛01 |
评测结果 |
C |
题目名称 |
算24点 |
最终得分 |
0 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-09-04 21:01:11 |
显示代码纯文本
{$r+}
program point24;
var
a:array[1..4] of integer;
list:array[1..25,1..4] of integer;
b:array[1..4] of boolean;
fh:array[1..3] of char;
fh2:array[1..3] of integer;
n,s,i1,j1:integer;
procedure pai(step:integer);
var
i:integer;
begin
if step>4 then
begin
s:=s+1;
list[s]:=list[s-1];
exit
end;
for i:=1 to 4 do
begin
if b[i] then
begin
list[s,step]:=a[i];
b[i]:=false;
pai(step+1);
b[i]:=true
end
end
end;
procedure pointt(last,step:integer);
begin
if (step>4) then
begin
if last=24 then
begin
writeln(list[i1,1],fh[1],list[i1,2],'=',fh2[2]);
writeln(fh2[2],fh[2],list[i1,3],'=',fh2[3]);
writeln(fh2[3],fh[3],list[i1,4],'=24');
close(input);
close(output);
halt
end;
exit
end;
fh[step-1]:='+';
fh2[step-1]:=last;
pointt(last+list[i1,step],step+1);
if last-list[i1,step]>=1 then
begin
fh[step-1]:='-';
fh2[step-1]:=last;
pointt(last-list[i1,step],step+1)
end;
if last mod list[i1,step]=0 then
begin
fh[step-1]:='/';
fh2[step-1]:=last;
pointt(last div list[i1,step],step+1)
end;
fh[step-1]:='*';
fh2[step-1]:=last;
pointt(last*list[i1,step],step+1)
end;
begin
assign(input,'point24.in');
reset(input);
assign(output,'point24.out');
rewrite(output);
for i1:=1 to 4 do
begin
read(a[i1]);
b[i1]:=true
end;
s:=1;
pai(1);
for i1:=1 to 24 do
begin
pointt(list[i1,1],2)
end;
writeln('No answer!');
close(input);
close(output)
end.