建议你多用几个for解决算了!

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i, j, k: integer;
      A, B: array[1..9] of Integer;
      str3, str1, str2 : String;
    begin
      caption := '';
      for i:=2 to 8 do //1234*9= 11106>4位,i不能取9, i取1,必定产生重复数字
      begin
        if (i=5) then  Continue;  //i不能取5, 必定产生重复数字
        for j:=1234 to 4987 do
        begin
           k := i * j;
           if k<9876 then
           begin
             a[1] := j div 1000;
             a[2] := (j mod 1000) div 100;
             a[3] := (j mod 100) div 10;
             a[4] := j mod 10;         a[5] := k div 1000;
             a[6] := (k mod 1000) div 100;
             a[7] := (k mod 100) div 10;
             a[8] := k mod 10;         if (a[4]=5)  then  Continue;  //i不能取5, 必定产生重复数字         a[9] := i;
             b := a;
             sort(b);         if (b[1]=1) and (b[2]=2) and (b[3]=3) and (b[4]=4) and (b[5]=5) and (b[6]=6) and (b[7]=7) and (b[8]=8) and (b[9]=9) then
             begin
               str1 := inttostr(a[9]);
               str2 := inttostr(a[1]) + inttostr(a[2]) + inttostr(a[3]) + inttostr(a[4]);
               str3 := inttostr(a[5]) + inttostr(a[6]) + inttostr(a[7]) + inttostr(a[8]);
               caption := caption + '---' + str1 + ' * ' + str2 + ' = ' + str3;
             end;
           end;
        end;
      end;
    end;procedure TForm1.Sort(var A: array of Integer);
    var
      I, J, T: Integer;
    begin
      for I := High(A) downto Low(A) do
        for J := Low(A) to High(A) - 1 do
          if A[J] > A[J + 1] then
          begin
            T := A[J];
            A[J] := A[J + 1];
            A[J + 1] := T;
          end;
    end;
    输出是:4 * 1738 = 6592 --- 4 * 1963 = 7852
      

  2.   

    4*1738=6952
    4*1963=7852
    import java.util.*;
    import java.io.*;
    import java.net.*;public class test {
      public static void main(String args[]) {
        Vector j = new Vector();
        for (int X = 1; X < 10; X++) {
          j.add(Integer.toString(X));
          for (int A = 1; A < 10; A++) {
            if (j.contains(Integer.toString(A)))continue;
            j.add(Integer.toString(A));
            for (int B = 1; B < 10; B++) {
              if (j.contains(Integer.toString(B)))continue;
              j.add(Integer.toString(B));
              for (int C = 1; C < 10; C++) {
                if (j.contains(Integer.toString(C)))continue;
                j.add(Integer.toString(C));
                for (int D = 1; D < 10; D++) {
                  if (j.contains(Integer.toString(D)))continue;
                  j.add(Integer.toString(D));              String result = Integer.toString(Integer.parseInt(j.elementAt(0).
                      toString()) *
                                                   Integer.parseInt(j.elementAt(1).
                      toString() +
                      j.elementAt(2).toString() +
                      j.elementAt(3).toString() +
                      j.elementAt(4).toString()));
                  if (result.indexOf("0") > 0 || result.length() == 5) {
                    j.removeElementAt(4);
                    continue;
                  }
                  String r1 = result.substring(0, 1);
                  if (j.contains(r1)) {
                    j.removeElementAt(4);
                    continue;
                  }
                  else {
                    j.add(r1);
                  }
                  String r2 = result.substring(1, 2);
                  if (j.contains(r2)) {
                    j.removeElementAt(5);
                    j.removeElementAt(4);
                    continue;
                  }
                  else {
                    j.add(r2);
                  }
                  String r3 = result.substring(2, 3);
                  if (j.contains(r3)) {
                    j.removeElementAt(6);
                    j.removeElementAt(5);
                    j.removeElementAt(4);
                    continue;
                  }
                  else {
                    j.add(r3);
                  }
                  String r4 = result.substring(3, 4);
                  if (j.contains(r4)) {
                    j.removeElementAt(7);
                    j.removeElementAt(6);
                    j.removeElementAt(5);
                    j.removeElementAt(4);
                    continue;
                  }
                  else {
                    j.add(r4);
                  }              System.out.println(j.elementAt(0) + "*" + j.elementAt(1) +
                                     j.elementAt(2) + j.elementAt(3) +
                                     j.elementAt(4) + "=" + result);              j.removeElementAt(8);
                  j.removeElementAt(7);
                  j.removeElementAt(6);
                  j.removeElementAt(5);
                  j.removeElementAt(4);            }
                j.removeElementAt(3);
              }
              j.removeElementAt(2);
            }
            j.removeElementAt(1);
          }
          j.removeElementAt(0);
        }
      }
    }
      

  3.   

    to:strayerctx(一夜风雨) (
    你那个用delphi做的?
      

  4.   

    /**A*BCDE=FGHT
     *每个数不能相等
     */
     public class MultiTest
     {
      private int a,b,c,d,e,f,g,h,i;
      public void Multi()
      {
      for(int a=1;a<10;a++)
      {
      for(int b=1;b<10;b++)
      {
      if(b != a)
      {
      for(int c=1;c<10;c++)
      {
      if(c != a && c != b)
      {
      for(int d=1;d<10;d++)
      {
      if(d != a && d != b && d != c)
      {
      for(int e=1;e<10;e++)
      {
      if(e != a && e != b && e != c && e!= d)
      {
      for(int f=1;f<10;f++)
      {
      if(f != a && f!= b && f!= c && f!= d && f != e)
      {
      for(int g=1;g<10;g++)
      {
      if(g !=a && g != b && g != c && g != d && g != e && g != f)
      {
      for(int h=1;h<10;h++)
      {
      if(h != a && h != b && h != c && h != d && h != e && h != f && h != g)
      {
      for(int i=1;i<10;i++)
      {
      if(i != a && i != b && i != c && i != d && i != e && i != f && i != g && i != h)
      {
      if((a*(b*1000+c*100+d*10+e)) == (f*1000+g*100+h*10+i))
      {
      // if(b != 0 && f != 0)
      int x = (b * 1000 + c * 100 + d * 10 + e);
      int y = (f * 1000 + g * 100 + h * 10 + i);
          System.out.println(a + "*" + x + "=" + y);
     
     
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      }
      public static void main(String [] args)
      {
      MultiTest Multi = new MultiTest();
      Multi.Multi();
      }
     }