记录编号 2514 评测结果 AAAAAAAAAA
题目名称 算24点 最终得分 100
用户昵称 Gravatarfrancis 是否通过 通过
代码语言 Pascal 运行时间 0.001 s
提交时间 2008-09-22 19:35:30 内存使用 0.12 MiB
显示代码纯文本
program point24;
const
fin='point24.in';
fou='point24.out';
var
a:array[1..4]of longint;
b:array[1..4]of boolean;
c:array[1..3,1..3]of longint;
ch:array[1..3]of char;
total,x,y,p,q,i,j:longint;
f1,f2:text;

procedure init;
begin
assign(f1,fin); assign(f2,fou);
reset(f1); rewrite(f2);
for i:=1 to 4 do
 read(f1,a[i]);
end;

procedure put(total:longint);
var
i,j:longint;
begin
if total=24 then
begin
 for i:=1 to 3 do
 writeln(f2,c[i,1],ch[i],c[i,2],'=',c[i,3]);
 close(f1); close(f2); halt;
end;
end;

procedure print(x,y:longint);
begin
if x>=y then begin c[3,1]:=x; c[3,2]:=y; end
        else begin c[3,1]:=y; c[3,2]:=x; end;

  c[3,3]:=c[3,1]+c[3,2]; ch[3]:='+'; put(c[3,3]);
  c[3,3]:=c[3,1]-c[3,2]; ch[3]:='-'; put(c[3,3]);
  c[3,3]:=c[3,1]*c[3,2]; ch[3]:='*'; put(c[3,3]);
  if (c[3,2]<>0)and((c[3,1]/c[3,3])=trunc(c[3,1]/c[3,2]))then
   begin c[3,3]:=trunc(c[3,1]/c[3,2]); ch[3]:='/'; put(c[3,3]); end;
end;

procedure go;
var
i,j,k,t:longint;
begin
k:=c[1,3];
for i:=1 to 4 do
 if b[i]=false then
 begin
  b[i]:=true;
  if k>=a[i] then begin c[2,1]:=k; c[2,2]:=a[i]; end
             else begin c[2,1]:=a[i]; c[2,2]:=k; end;
  for j:=1 to 4 do
    if b[j]=false then t:=a[j];
  c[2,3]:=c[2,1]+c[2,2]; ch[2]:='+'; print(c[2,3],t);
  c[2,3]:=c[2,1]-c[2,2]; ch[2]:='-'; print(c[2,3],t);
  c[2,3]:=c[2,1]*c[2,2]; ch[2]:='*'; print(c[2,3],t);
  if (c[2,2]<>0)and((c[2,1]/c[2,2])=trunc(c[2,1]/c[2,2]))then
   begin c[2,3]:=trunc(c[2,1]/c[2,2]); ch[2]:='/'; print(c[2,3],t); end;
  b[i]:=false;
 end;
end;

begin
init;
for i:=1   to 4 do
 for j:=i+1 to 4 do
  begin
   b[i]:=true; b[j]:=true;
   if a[i]>=a[j] then begin c[1,1]:=a[i]; c[1,2]:=a[j]; end
                 else begin c[1,1]:=a[j]; c[1,2]:=a[i]; end;
    c[1,3]:=c[1,1]+c[1,2]; ch[1]:='+'; go;
    c[1,3]:=c[1,1]-c[1,2]; ch[1]:='-'; go;
    c[1,3]:=c[1,1]*c[1,2]; ch[1]:='*'; go;
    if (c[1,2]<>0)and((c[1,1]/c[1,1])=trunc(c[1,1]/c[1,1])) then
       begin c[1,3]:=trunc(c[1,1]/c[1,1]); go; ch[1]:='/'; end;
    b[i]:=false; b[j]:=false;
  end;
write(f2,'No answer!');
close(f1); close(f2);
end.