记录编号 18569 评测结果 AAAWWWAAWW
题目名称 算24点 最终得分 50
用户昵称 Gravatar928479 是否通过 未通过
代码语言 Pascal 运行时间 0.001 s
提交时间 2010-09-16 19:35:57 内存使用 0.11 MiB
显示代码纯文本
program aa;

type arr=array[1..4]of integer;
var
  a:arr;
  r:array[1..3,1..4]of integer;
  i:integer;
  f:text;

procedure print;
var i,j:integer;
begin
 for i:=1 to 3 do
 begin
  for j:=1 to 4 do
   if j=2 then
    case r[i,j]of
    1:write(f,'+');
    2:write(f,'-');
    3:write(f,'*');
    4:write(f,'/') ;
    end
   else
   if j=4 then
    write(f,'=',r[i,j])
   else write(f,r[i,j]);
   writeln(f,' ');
 end;
end;

procedure try(k:integer;a:arr);
 var x,y,i,j,l,m,t,o:integer;
  e:arr;
 begin
 m:=k+1;
 if(k=3)and(a[1]=24)then
  begin
   print;
   close(f);
   halt;
  end
 else
  for i:=1 to 3-k do
  begin
   j:=i+1;
   x:=a[i];y:=a[j];
   r[m,1]:=x;r[m,3]:=y;r[m,4]:=-1;
   t:=0;
   for l:=1 to i-1 do begin inc(t);e[t]:=a[l];end;
   inc(t);o:=t;
   for l:=i+2 to 4-k do begin inc(t);e[t]:=a[l];end;
   for l:=1 to 4 do
    begin
     case l of
     1:r[m,4]:=x+y;
     2:r[m,4]:=x-y;
     3:r[m,4]:=x*y;
     4:if y<>0 then if x mod y=0 then r[m,4]:=x div y;
     end;
     if r[m,4]>=0 then
      begin
      e[o]:=r[m,4];
      r[m,2]:=l;
      try(m,e);
      end;
    end;
  end;
end;

begin
  assign(f,'point24.in');
  reset(f);
 for i:=1 to 4 do
  read(f,a[i]);
 close(f);

 assign(f,'point24.out');
 rewrite(f);

  try(0,a);

 writeln(f,'No answer!');
 close(f);

end.