将1-9这9个数字分成三组(每个数字只能使用一次)

1个回答

  • program tianshu;

    var bo:array[1..9]of integer;

    a,b,c,j:integer;

    begin

    for a:=123 to 329 do

    begin

    fillchar(bo,sizeof(bo),0);

    j:=0;

    b:=a*2;

    c:=a*3;

    if (a mod 100)and(bo[a mod 10]=0) then

    begin

    inc(j);

    bo[a mod 10]:=1;

    end;

    if ((a div 10)mod 100)and(bo[(a div 10)mod 10]=0) then

    begin

    inc(j);

    bo[(a div 10)mod 10]:=1;

    end;

    if (a div 1000)and(bo[a div 100]=0) then

    begin

    inc(j);

    bo[a div 100]:=1;

    end;

    if (b mod 100)and(bo[b mod 10]=0) then

    begin

    inc(j);

    bo[b mod 10]:=1;

    end;

    if ((b div 10)mod 100)and(bo[(b div 10)mod 10]=0) then

    begin

    inc(j);

    bo[(b div 10)mod 10]:=1;

    end;

    if (b div 1000)and(bo[b div 100]=0) then

    begin

    inc(j);

    bo[b div 100]:=1;

    end;

    if (c mod 100)and(bo[c mod 10]=0) then

    begin

    inc(j);

    bo[c mod 10]:=1;

    end;

    if ((c div 10)mod 100)and(bo[(c div 10)mod 10]=0) then

    begin

    inc(j);

    bo[(c div 10)mod 10]:=1;

    end;

    if (c div 1000)and(bo[c div 100]=0) then

    begin

    inc(j);

    bo[c div 100]:=1;

    end;

    if j=9 then writeln(a,' ',b,' ',c);

    end;

    end.