有朋友能帮忙转化成DELPHI的代码吗?
var nowcards:Array = [10,10,6,3,1]//其中J,Q,K已经转换为10function testNN(targetcards:Array){    var tmp1:Boolean = false    var tmp2:Boolean = false    //tmp1记录是否有3张组成10    //tmp2记录是否是“牛牛”    for(var a=0;a<=2;a++){        for(var b=a+1;b<=3;b++){             for(var c=b+1;c<=4;c++){                   if((targetcards[a]+targetcards[b]+targetcards[c])%10 == 0){                          tmp1 = true                          var tmp3:Number = 0                          //tmp3是暂时保存数据用的                          for(var j=0;j<=4;j++){                               if(j != a && j != b && j != c){                                     tmp3+= targetcards[j]                               }                          }                          if(tmp3%10 == 0){                               tmp2 = true                          }                   }             }        }    }    //此函数运算到这,tmp2和tmp1已经记录了牌是否是“牛牛”和是否有3张加和是10倍数    //return部分未写出,可以看着办-_-}

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}var
      nowcards: array[0..4] of integer = (10, 10, 6, 3, 1);function testNN(targetcards: array of integer): integer;
    var
      tmp1: boolean;
      tmp2: boolean;
      tmp3: integer;
      a, b, c: integer;
      i, j : integer;
    begin
      for a := 0 to 2 do
        for b := a + 1 to 3 do
          for c := b + 1 to 4 do
            if (targetcards[a] + targetcards[b] + targetcards[c]) div 10 = 0 then
            begin
              tmp1 := True;
              for j := 0 to 4 do
                if (j <> a) and (j<> b) and (j <> c) then
                  tmp3 := tmp3 + targetcards[j]
            end;
      if (tmp3 div 10) = 0 then
        tmp2 := True;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      testNN(nowcards);
    end;end.不知何为牛牛算法!
      

  2.   

    if (tmp3 div 10) = 0 then
        tmp2 := True;这里要改成
    if (tmp3 mod 10) = 0 then
        tmp2 := True;
      

  3.   

    var
      nowcards: array[0..4] of integer = (10, 10, 6, 3, 1);function testNN(targetcards: array of integer): integer;
    var
      tmp1: boolean;
      tmp2: boolean;
      tmp3: integer;
      a, b, c: integer;
      i, j : integer;
    begin
      result:=-1;
      for a := 0 to 2 do
        for b := a + 1 to 3 do
          for c := b + 1 to 4 do
            if (targetcards[a] + targetcards[b] + targetcards[c]) mod 10 = 0 then
            begin
              tmp1 := True;
              for j := 0 to 4 do
                if (j <> a) and (j<> b) and (j <> c) then
                  tmp3 := tmp3 + targetcards[j]
            end;
      if (tmp3 mod 10) = 0 then
        tmp2 := True;
      //以下返回输出
      //result:=需要返回的结果
    end;