比赛 练习赛01 评测结果 AAAAAWAAAA
题目名称 算24点 最终得分 90
用户昵称 .Xmz 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-09-04 21:26:52
显示代码纯文本
program xmz;
var
 f1,f2:text;
 a:integer;
 da,xiao,x:array[1..4]of integer;
 ch:array[1..4]of char;
procedure sou(n:integer);
 var
  i,j,k:integer;
  q:array[1..4]of integer;
 begin
  if n<>1 then begin
  for i:=1 to 4 do
   q[i]:=x[i];
  for i:=1 to 3 do
   for j:=i+1 to 4 do
     if (x[i]<>0)and(x[j]<>0) then
     begin
      if x[i]>=x[j] then
       begin
        da[n]:=x[i];xiao[n]:=x[j];ch[n]:='+';x[i]:=x[i]+x[j];x[j]:=0;sou(n-1);for k:=1 to 4 do x[k]:=q[k];
        da[n]:=x[i];xiao[n]:=x[j];ch[n]:='*';x[i]:=x[i]*x[j];x[j]:=0;sou(n-1);for k:=1 to 4 do x[k]:=q[k];
        if x[i]<>x[j] then begin da[n]:=x[i];xiao[n]:=x[j];ch[n]:='-';x[i]:=x[i]-x[j];x[j]:=0;sou(n-1);
        for k:=1 to 4 do x[k]:=q[k];end;
        if x[i] mod x[j]=0 then
        begin da[n]:=x[i];xiao[n]:=x[j];ch[n]:='/';x[i]:=x[i] div x[j];x[j]:=0;sou(n-1);
        for k:=1 to 4 do x[k]:=q[k];end;
       end
      else
       begin
        da[n]:=x[j];xiao[n]:=x[i];ch[n]:='+';x[i]:=x[i]+x[j];x[j]:=0;sou(n-1);for k:=1 to 4 do x[k]:=q[k];
        da[n]:=x[j];xiao[n]:=x[i];ch[n]:='*';x[i]:=x[i]*x[j];x[j]:=0;sou(n-1);for k:=1 to 4 do x[k]:=q[k];
        da[n]:=x[j];xiao[n]:=x[i];ch[n]:='-';x[i]:=x[j]-x[i];x[j]:=0;sou(n-1);for k:=1 to 4 do x[k]:=q[k];
        if x[j] mod x[i]=0 then begin da[n]:=x[i];xiao[n]:=x[j];ch[n]:='/';x[i]:=x[j] div x[i];x[j]:=0;sou(n-1);
        for k:=1 to 4 do x[k]:=q[k];end;
       end;
     end;
  end
  else
   if x[1]=24 then
   begin
    for i:=4 downto 2 do
     begin
     if ch[i]='+' then writeln(f2,da[i],ch[i],xiao[i],'=',da[i]+xiao[i]);
     if ch[i]='-' then writeln(f2,da[i],ch[i],xiao[i],'=',da[i]-xiao[i]);
     if ch[i]='*' then writeln(f2,da[i],ch[i],xiao[i],'=',da[i]*xiao[i]);
     if ch[i]='/' then writeln(f2,da[i],ch[i],xiao[i],'=',da[i] div xiao[i]);
     end;
    close(f1);close(f2);halt;
   end;
 end;
begin
 assign(f1,'point24.in');assign(f2,'point24.out');
 reset(f1);rewrite(f2);

  for a:=1 to 4 do
   read(f1,x[a]);
 sou(4);
 writeln(f2,'No answer!');
 close(f1);close(f2);
end.