比赛 |
20100914 |
评测结果 |
AAAWAWAAWA |
题目名称 |
算24点 |
最终得分 |
70 |
用户昵称 |
Des. |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-09-14 20:33:03 |
显示代码纯文本
program point24;
var l,a,b,j:array[1..4]of integer;
s:array[1..4]of char;
t,k,m,n,i:longint;
function max(x,y:longint):longint;
begin
if a[x]>y then max:=a[x] else max:=y;
end;
function min(x,y:longint):longint;
begin
if a[x]<y then min:=a[x] else min:=y;
end;
function max1(x,y:longint):longint;
begin
if x>y then max1:=x else max1:=y;
end;
function min1(x,y:longint):longint;
begin
if x<y then min1:=x else min1:=y;
end;
function max2(x,y:longint):longint;
begin
if a[x]>a[y] then max2:=a[x] else max2:=a[y];
end;
function min2(x,y:longint):longint;
begin
if a[x]<a[y] then min2:=a[x] else min2:=a[y];
end;
procedure pp;
var t,k:longint;
p:boolean;
begin
p:=false;
if j[2]+j[4]=24 then
begin
p:=true;
s[3]:='+';
end
else if j[2]-j[4]=24 then
begin
p:=true;
s[3]:='-';
end
else if j[2]*j[4]=24 then
begin
p:=true;
s[3]:='*';
end
else if (j[2] div j[4]=24)and(j[2] mod j[4]=0) then
begin
p:=true;
s[3]:='/';
end;
if p then
begin
writeln(max2(l[1],l[2]),s[2],min2(l[2],l[1]),'=',j[2]);
writeln(max2(l[3],l[4]),s[4],min2(l[4],l[1]),'=',j[4]);
writeln(max1(j[2],j[4]),s[3],min1(j[4],j[2]),'=',24);
close(output);
halt;
end;
end;
procedure sou(i:longint);
var t,k:longint;
begin
if i=5 then
begin
if (j[4]=24)and(s[3]<>'?') then
begin
for t:=2 to 4 do
writeln(max(l[t],j[t-1]),s[t],min(l[t],j[t-1]),'=',j[t]);
close(output);
halt;
end
else if s[3]='?' then pp;
end;
for t:=1 to 4 do
if b[t]=0 then
begin
l[i]:=t;
b[t]:=1;
s[i]:='+';
j[i]:=j[i-1]+a[t];
sou(i+1);
s[i]:='.';
j[i]:=0;
b[t]:=0;
l[i]:=0;
if j[i-1]-a[t]>0 then
begin
l[i]:=t;
b[t]:=1;
s[i]:='-';
j[i]:=j[i-1]-a[t];
sou(i+1);
s[i]:='.';
j[i]:=0;
b[t]:=0;
l[i]:=0;
end;
l[i]:=t;
b[t]:=1;
s[i]:='*';
j[i]:=j[i-1]*a[t];
sou(i+1);
s[i]:='.';
j[i]:=0;
b[t]:=0;
l[i]:=0;
if j[i-1] mod a[t]=0 then
begin
l[i]:=t;
b[t]:=1;
s[i]:='/';
j[i]:=j[i-1] div a[t];
sou(i+1);
s[i]:='.';
j[i]:=0;
b[t]:=0;
l[i]:=0;
end;
end;
if i=3 then
for t:=1 to 4 do
if (b[t]=0) then
begin
l[i]:=t;
b[t]:=1;
s[i]:='?';
j[i]:=a[t];
sou(i+1);
s[i]:='.';
j[i]:=0;
b[t]:=0;
l[i]:=0;
end;
end;
begin
assign(input,'point24.in');
reset(input);
assign(output,'point24.out');
rewrite(output);
for t:=1 to 4 do
read(a[t]);
for t:=1 to 4 do
begin
l[1]:=t;
b[t]:=1;
j[1]:=a[t];
sou(2);
b[1]:=0;
end;
writeln('No answer!');
close(input);
close(output);
end.