记录编号 12244 评测结果 AAAWAWAWWA
题目名称 算24点 最终得分 60
用户昵称 Gravatarreamb 是否通过 未通过
代码语言 Pascal 运行时间 0.002 s
提交时间 2009-09-08 13:12:00 内存使用 0.11 MiB
显示代码纯文本
program ershisidian;
var
  biaozhi:array[1..4]of boolean;
  s,k:integer;
  g:boolean;
  a,jilu1,jilu2:array[1..8] of integer;
procedure dayin;
var
  z:integer;
begin
  for z:=2 to 4 do
  begin
    if jilu2[z]=1 then
      if jilu1[2*z-1]>=jilu1[2*z] then
        writeln (jilu1[2*z-1],'+',jilu1[2*z],'=',jilu1[2*z-1]+jilu1[2*z])
      else
        writeln (jilu1[2*z],'+',jilu1[2*z-1],'=',jilu1[2*z-1]+jilu1[2*z]);
    if jilu2[z]=2 then
      writeln (jilu1[2*z-1],'-',jilu1[2*z],'=',jilu1[2*z-1]-jilu1[2*z]);
    if jilu2[z]=3 then
      if jilu1[2*z-1]>=jilu1[2*z] then
        writeln (jilu1[2*z-1],'*',jilu1[2*z],'=',jilu1[2*z-1]*jilu1[2*z])
      else
        writeln (jilu1[2*z],'*',jilu1[2*z-1],'=',jilu1[2*z-1]*jilu1[2*z]);
    if jilu2[z]=4 then
      writeln (jilu1[2*z-1],'/',jilu1[2*z],'=',jilu1[2*z-1] div jilu1[2*z])
  end
end;
procedure search (x:integer);
var
  i,j:integer;
  g2:boolean;
begin
  if x<5 then
  begin
  for i:=1 to 4 do
  begin
    if x=1 then
    begin
      s:=a[i];
      biaozhi[i]:=false;
      search(x+1)
    end;
    for j:=1 to 4 do
    begin
      if biaozhi[i] then
      begin
        g2:=true;
        if j=1 then
        begin
          g2:=false;
          jilu1[2*x-1]:=s;
          jilu1[2*x]:=a[i];
          jilu2[x]:=j;
          s:=s+a[i];
          biaozhi[i]:=false
        end;
        if (j=2)and(s-a[i]>0) then
        begin
          g2:=false;
          jilu1[2*x-1]:=s;
          jilu1[2*x]:=a[i];
          jilu2[x]:=j;
          s:=s-a[i];
          biaozhi[i]:=false
        end;
        if j=3 then
        begin
          g2:=false;
          jilu1[2*x-1]:=s;
          jilu1[2*x]:=a[i];
          jilu2[x]:=j;
          s:=s*a[i];
          biaozhi[i]:=false
        end;
        if (j=4)and(s mod a[i]=0) then
        begin
          g2:=false;
          jilu1[2*x-1]:=s;
          jilu1[2*x]:=a[i];
          jilu2[x]:=j;
          s:=s div a[i];
          biaozhi[i]:=false
        end;
        g:=true;
        for k:=1 to 4 do
        if biaozhi[k] then
          g:=false;
        if (g)and(x=4)and(s=24) then
        begin
          dayin;
          close (input);
          close (output);
          halt
        end
        else
          search(x+1);
        if g2=false then
        begin
          if j=1 then
          begin
            biaozhi[i]:=true;
            s:=s-a[i];
          end;
          if j=2 then
          begin
            biaozhi[i]:=true;
            s:=s+a[i];
          end;
          if j=3 then
          begin
            biaozhi[i]:=true;
            s:=s div a[i];
          end;
          if j=4 then
          begin
            biaozhi[i]:=true;
            s:=s*a[i];
          end
        end
      end
    end
  end
  end
end;
begin
  assign (input,'point24.in');
  reset (input);
  assign (output,'point24.out');
  rewrite (output);
  for k:=1 to 4 do
  begin
    read (a[k]);
    biaozhi[k]:=true
  end;
  search(1);
  write('No answer!');
  close (input);
  close (output)
end.