請問如何列出所有組合 |
尚未結案
|
shing.net
中階會員 發表:207 回覆:124 積分:66 註冊:2002-03-16 發送簡訊給我 |
|
shing.net
中階會員 發表:207 回覆:124 積分:66 註冊:2002-03-16 發送簡訊給我 |
|
mine
中階會員 發表:28 回覆:129 積分:56 註冊:2004-03-31 發送簡訊給我 |
hihi
不知合不合您用
procedure TForm1.Button1Click(Sender: TObject); var ta:array[0..3]of byte; j,b,i:integer; begin b:=2; for i:=0 to 3 do begin ta[i]:=i 1; end; if b>=2 then begin Repeat for i:=0 to 3 do begin for j:=0 to 3 do begin memo1.text:=memo1.text inttostr(ta[i]) inttostr(ta[j]) ' '; end; end; b:=b-1; until b<=1 ; end;有些地方可能要改:P 搞不懂!搞不懂!永遠都搞不懂!! |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
procedure TForm1.Button1Click(Sender: TObject); const A: array[0..3] of Integer = (1,2,3,4); Length(A)進位系統 function IntToStr_YouWant(Value: Integer): string; var I: Integer; begin Result := ''; I := Length(A); repeat Result := IntToStr(A[Value mod Length(A)]) ',' Result; Value := Value div Length(A); Dec(I); until I = 0; Result := '{' Result; Result[Length(Result)] := '}'; end; function GetResultList(ElementCount, ElementPerSet: Integer): TStringList; var I, Count: Integer; begin Result := TStringList.Create; if ElementPerSet > ElementCount then Exit; if(ElementCount > 0)and(ElementPerSet > 0) then begin Count := Round(IntPower(ElementCount,ElementPerSet)); for I := 0 to Count-1 do Result.Add(IntToStr_YouWant(I)); end; end; var B: Integer; L: TStringList; begin ShowMessage(IntToStr(Length(A))); B := 4; L := GetResultList(Length(A),B); if Assigned(L) then try Label1.Caption := IntToStr(L.Count); ListBox1.Items.Text := L.Text; finally FreeAndNil(L); end; end; |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
修正!
function IntToStr_YouWant(Value, ElementPerSet: Integer): string;<--傳入數字個數 var I: Integer; begin Result := ''; if ElementPerSet > 0 then begin I := ElementPerSet;<--限制數字個數 repeat Result := IntToStr(A[Value mod Length(A)]) ',' Result; Value := Value div Length(A); Dec(I); until I = 0; Result := '{' Result; Result[Length(Result)] := '}'; end; end; function GetResultList(ElementCount, ElementPerSet: Integer): TStringList; var I, Count: Integer; begin Result := TStringList.Create; if ElementPerSet > ElementCount then Exit; if(ElementCount > 0)and(ElementPerSet > 0) then begin Count := Round(IntPower(ElementCount,ElementPerSet)); for I := 0 to Count-1 do Result.Add(IntToStr_YouWant(I, ElementPerSet));<--傳入數字個數 end; end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |