#2 怎么错了

P1618 三连击(升级版)

oceanlin @ 2017-05-05 21:56:55

var i,j,k,x,x2,x3,y,y2,y3,o,r,rr,rrr:longint;
    a,b:array[0..100] of 0..1;
    flag:boolean;
begin
 readln(r,rr,rrr);
 flag:=false;
 if rr>rrr then begin
  i:=rr;
  rr:=rrr;
  rrr:=i;
 end; 
 if r>rr then begin
  i:=r;
  r:=rr;
  rr:=i;
 end; 
 if rr>rrr then begin
  i:=rr;
  rr:=rrr;
  rrr:=i;
 end; 
 for i:=1 to 9 do
 begin
  a[i]:=1;
  x:=i*100;
  for j:=1 to 9 do
  begin
   a[j]:=1;
   x:=x+j*10;
   for k:=1 to 9 do
   if (i<>j)and(k<>j)and(i<>k) then begin
    a[k]:=1;
    b:=a;
    x:=x+k;
    if (x/r*rr<>trunc(x/r*rr))or(x/r*rrr<>trunc(x/r*rrr)) then begin
     x:=x-k;
     a[k]:=0;
     continue;
    end
    else begin
     x2:=(x div r)*rr;
     x3:=(x div r)*rrr;
    end;
    y:=x2 mod 10;
    y2:=(x2 div 10) mod 10;
    y3:=x2 div 100;
    if (b[y]=1)or(b[y2]=1)or(b[y3]=1)or(y=0)or(y2=0)or(y3=0)or(y3>=10)or(y=y2)or(y=y3)or(y2=y3) then begin
     a[k]:=0;
     x:=x-k;
     continue;
    end
    else begin
     b[y]:=1;
     b[y2]:=1;
     b[y3]:=1;
    end;
    y:=x3 mod 10;
    y2:=(x3 div 10) mod 10;
    y3:=x3 div 100;
    if (b[y]=1)or(b[y2]=1)or(b[y3]=1)or(y=0)or(y2=0)or(y3=0)or(y3>=10)or(y=y2)or(y=y3)or(y2=y3) then begin
     a[k]:=0;
     x:=x-k;
     continue;
    end
    else begin 
     flag:=true;
     writeln(x,' ',x2,' ',x3);
    end;
    x:=x-k;
   end;
   x:=x-j*10;
   a[j]:=0;
  end;
  x:=0;
  a[i]:=0;
 end;
 if not flag then writeln('No!!!');
end.

by oceanlin @ 2017-05-05 22:13:38

已解决


|