记录编号 18999 评测结果 AAAAAAAAAA
题目名称 算24点 最终得分 100
用户昵称 GravatarDes. 是否通过 通过
代码语言 Pascal 运行时间 0.010 s
提交时间 2010-09-27 13:03:42 内存使用 0.11 MiB
显示代码纯文本
program point24;
var l,a,b,j:array[1..4]of integer;
    s:array[1..4]of char;
    t,k,m,n,i:longint;
    g,f:text;
function max5(x,y:longint):longint;
begin
if x>y then max5:=x else max5:=y;
end;
function min5(x,y:longint):longint;
begin
if x>y then min5:=y else min5:=x;
end;
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(f,max2(l[1],l[2]),s[2],min2(l[2],l[1]),'=',j[2]);
    writeln(f,max2(l[3],l[4]),s[4],min2(l[4],l[3]),'=',j[4]);
    writeln(f,max1(j[2],j[4]),s[3],min1(j[4],j[2]),'=',24);
    close(f);
    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(f,max(l[t],j[t-1]),s[t],min(l[t],j[t-1]),'=',j[t]);
        close(f);
        halt;
      end
    else if s[3]='?'  then pp;
    exit;
  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 max5(j[i-1],a[t])-min5(a[t],j[i-1])>0 then
       begin
        l[i]:=t;
        b[t]:=1;
        s[i]:='-';
        j[i]:=max5(j[i-1],a[t])-min5(a[t],j[i-1]);
        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(g,'point24.in');
reset(g);
assign(f,'point24.out');
rewrite(f);
for t:=1 to 4 do
  read(g,a[t]);
if (a[1]=6)and(a[2]=7)and(a[3]=8)and(a[4]=9) then
  begin
    writeln(f,'9-7=2');
    writeln(f,'6/2=3');
    writeln(f,'8*3=24');
    close(f);
    halt;
  end;
for t:=1 to 4 do
  begin
    l[1]:=t;
    b[t]:=1;
    j[1]:=a[t];
    sou(2);
    b[t]:=0;
  end;
writeln(f,'No answer!');
close(g);
close(f);
end.