读书人

多个数组互相组合,但不能出现重复.该如

发布时间: 2012-04-06 12:22:24 作者: rapoo

多个数组互相组合,但不能出现重复.

Delphi(Pascal) code
   Letter: Array[0..25] of string = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');  Digital: Array[0..9] of string = ('00', '11', '22', '33', '44', '55', '66', '77', '88', '99');  Special: Array[0..4] of string = ('!!!', '@@@', '###', '$$$', '%%%');


多个数组混合在一起,互相组合并且不能重复,每个组合至少又两个数组组成
比如:
A00
00A
A!!!
!!!A
!!!00
00!!!
A00!!!
!!!00A
A!!!00
00A!!!
!!!A00
等等~
最好能有例子代码,如果没有,求思路也好.

[解决办法]
2L有问题,看这个:
Delphi(Pascal) code
procedure TForm1.FormCreate(Sender: TObject);const  Letter: Array[0..25] of string = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');  Digital: Array[0..9] of string = ('00', '11', '22', '33', '44', '55', '66', '77', '88', '99');  Special: Array[0..4] of string = ('!!!', '@@@', '###', '$$$', '%%%');var  R: array of string;  procedure DoIt(L: Integer = 0; D: Integer = 0; S: Integer = 0; I: Integer = 0; Three: Boolean = True);  begin    if Length(R) = 0 then      SetLength(R, (Length(Letter)*Length(Digital)*Length(Special)*6)+        (Length(Letter)*Length(Digital)*2+Length(Letter)*Length(Special)*2+Length(Digital)*Length(Special)*2));    if Three then    begin      R[I] := Letter[L] + Digital[D] + Special[S];      Inc(I);      R[I] := Letter[L] + Special[S] + Digital[D];      Inc(I);      R[I] := Digital[D] + Letter[L] + Special[S];      Inc(I);      R[I] := Digital[D] + Special[S] + Letter[L];      Inc(I);      R[I] := Special[S] + Letter[L] + Digital[D];      Inc(I);      R[I] := Special[S] + Digital[D] + Letter[L];    end    else if L = -1 then    begin      R[I] := Digital[D] + Special[S];      Inc(I);      R[I] := Special[S] + Digital[D];    end else if D = -1 then    begin      R[I] := Letter[L] + Special[S];      Inc(I);      R[I] := Special[S] + Letter[L];    end else if S = -1 then    begin      R[I] := Letter[L] + Digital[D];      Inc(I);      R[I] := Digital[D] + Letter[L];    end;    if Three then      if S = High(Special) then      begin        if D = High(Digital) then          if L = High(Letter) then          begin            L := -1;            D := 0;            S := 0;            Three := False          end          else          begin            Inc(L);            D := 0;            S := 0;          end        else        begin          Inc(D);          S := 0;        end;      end else Inc(S)    else      if L = -1 then        if S = High(Special) then          if D = High(Digital) then          begin            L := 0;            D := -1;            S := 0          end else          begin            Inc(D);            S := 0          end        else Inc(S)      else if D = -1 then        if S = High(Special) then          if L = High(Letter) then          begin            L := 0;            D := 0;            S := -1;          end else          begin            Inc(L);            S := 0          end        else Inc(S)      else if S = -1 then        if D = High(Digital) then          if L = High(Letter) then Exit          else begin            Inc(L);            D := 0          end        else Inc(D);            Inc(I);    DoIt(L, D, S, I, Three);  end;  begin  DoIt;end; 

读书人网 >.NET

热点推荐