比赛 练习赛01 评测结果 AAAWWWAAAA
题目名称 算24点 最终得分 70
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-09-04 21:10:51
显示代码纯文本
program point24;
var
   sz:array[1..4]of integer;
   w:array[1..4]of char;
   i1,i2,i3,i4,j1,j2,j3:integer;
procedure p;
var
   s1,s2,s3:integer;
begin
     if j1=1 then s1:=sz[i1]+sz[i2];
     if j1=2 then s1:=abs(sz[i1]-sz[i2]);
     if j1=3 then s1:=sz[i1]*sz[i2];
     if (j1=4)and(sz[i1]<>0)and(sz[i2]<>0) then begin
        if (sz[i1]>sz[i2])and(sz[i1]mod sz[i2]=0) then s1:=sz[i1] div sz[i2] else if sz[i2]mod sz[i1]=0 then
           s1:=sz[i2] div sz[i1];
     end;
     if j2=1 then s2:=s1+sz[i3];
     if j2=2 then s2:=abs(s1-sz[i3]);
     if j2=3 then s2:=s1*sz[i3];
     if (j2=4)and(s1<>0)and(sz[i3]<>0) then begin
        if (s1>sz[i3])and(s1 mod sz[i3]=0) then s2:=s1 div sz[i3] else if sz[i3]mod s1=0 then s2:=sz[i3] div s1;
     end;
     if j3=1 then s3:=s2+sz[i4];
     if j3=2 then s3:=abs(s2-sz[i4]);
     if j3=3 then s3:=s2*sz[i4];
     if (j2=4)and(s2<>0)and(sz[i4]<>0) then begin
        if (s2>sz[i4])and(s2 mod sz[i4]=0) then s3:=s2 div sz[i4] else if sz[i4]mod s2=0 then s3:=sz[i4] div s2;
     end;
     if s3=24 then begin
        if sz[i1]>sz[i2] then writeln(sz[i1],w[j1],sz[i2],'=',s1) else writeln(sz[i2],w[j1],sz[i1],'=',s1);
        if s1>sz[i3] then writeln(s1,w[j2],sz[i3],'=',s2) else writeln(sz[i3],w[j2],s1,'=',s2);
        if s2>sz[i4] then writeln(s2,w[j3],sz[i4],'=',s3) else writeln(sz[i4],w[j2],s2,'=',s3);
        close(input);
        close(output);
        halt;
     end;
end;
begin
     assign(input,'point24.in');
     assign(output,'point24.out');
     reset(input);
     rewrite(output);
     readln(sz[1],sz[2],sz[3],sz[4]);
     w[1]:='+';
     w[2]:='-';
     w[3]:='*';
     w[4]:='/';
     for i1:=1 to 4 do
         for i2:=1 to 4 do
             if i1<>i2 then
                for i3:=1 to 4 do
                    if (i1<>i3)and(i2<>i3) then
                       for i4:=1 to 4 do
                           if (i1<>i4)and(i2<>i4)and(i3<>i4) then begin
                              for j1:=1 to 4 do
                                  for j2:=1 to 4 do
                                      for j3:=1 to 4 do
                                          p;
                           end;
     writeln('No answer!');
     close(input);
     close(output);
end.