比赛 |
NOIP_4 |
评测结果 |
AAAWAWAAAA |
题目名称 |
算24点 |
最终得分 |
80 |
用户昵称 |
cuixiaofei |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-19 22:11:32 |
显示代码纯文本
//na :cuixiaofei;
//da :08_09_19;
program point24;
var
a,ji,fu,jin :array[1..4] of longint;
f1,f2 :text;
procedure init;
var
i :longint;
begin
assign(f1,'point24.in');
reset(f1);
assign(f2,'point24.out');
rewrite(f2);
for i:=1 to 4 do
read(f1,a[i]);
fillchar(ji,sizeof(ji),0);
fillchar(fu,sizeof(fu),0);
end;
function keyi(x,y,f:longint):longint;
begin
keyi:=1;
if f=4 then
begin
if x mod y <>0 then
keyi:=0;
end;
if f=2 then
begin
if x<y then
keyi:=0;
end;
end;
function jisuan(x,y,f:longint):longint;
begin
if f=1 then
jisuan:=x+y;
if f=2 then
jisuan:=x-y;
if f=3 then
jisuan:=x*y;
if f=4 then
jisuan:=x div y;
end;
function zifu(i:longint):char;
begin
if i=1 then
zifu:='+';
if i=2 then
zifu:='-';
if i=3 then
zifu:='*';
if i=4 then
zifu:='/';
end;
procedure print1;
var
i,t1,t2,t :longint;
begin
t1:=a[jin[1]];
for i:=1 to 3 do
begin
t2:=a[jin[i+1]];
if (t1<t2) and (fu[i]<>2) and (fu[i]<>4) then
begin
t:=t1;
t1:=t2;
t2:=t;
end;
writeln(f2,t1,zifu(fu[i]),t2,'=',jisuan(t1,t2,fu[i]));
t1:=jisuan(t1,t2,fu[i]);
end;
end;
procedure sousuo(k,x,y:longint);
var
i,j :longint;
begin
if k=4 then
begin
for i:=1 to 4 do
begin
if (keyi(x,y,i)=1) and (jisuan(x,y,i)=24) then
begin
fu[k-1]:=i;
print1;
close(f1);
close(f2);
halt;
end;
end;
end
else
begin
for i:=1 to 4 do
begin
if keyi(x,y,i)=1 then
begin
fu[k-1]:=i;
for j:=1 to 4 do
if ji[j]=0 then
begin
ji[j]:=1;
jin[k+1]:=j;
sousuo(k+1,jisuan(x,y,i),a[j]);
jin[k+1]:=0;
ji[j]:=0;
end;
end;
end;
end;
end;
procedure main;
var
i,j :longint;
begin
for i:=1 to 4 do
if ji[i]=0 then
begin
ji[i]:=1;
for j:=1 to 4 do
if ji[j]=0 then
begin
jin[1]:=i;
jin[2]:=j;
ji[j]:=1;
sousuo(2,a[i],a[j]);
ji[j]:=0;
end;
ji[i]:=0;
end;
end;
procedure print2;
begin
writeln(f2,'No answer!');
close(f2);
close(f1);
end;
begin
init;
main;
print2;
end.