如何打印出15选3的全排列,(200分)

  • 主题发起人 主题发起人 12345
  • 开始时间 开始时间
1

12345

Unregistered / Unconfirmed
GUEST, unregistred user!
01*05*07*08*09*10*11*13*18*24*35*45*68*69*78对这个15个数选3个的全排列*号为分割<br>符号
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>const<br>&nbsp; a: array [1..15] of Integer = (1, 5, 7, 8, 9, 10, 11, 13, 18, 24, 35, 45, 68, 69, 78);<br><br>{$R *.dfm}<br><br>procedure Hahaha;<br>var<br>&nbsp; Stack: array [1..3] of Integer;<br>&nbsp; Top: Integer;<br>&nbsp; i: Integer;<br>&nbsp; s: string;<br><br>function Double: Boolean;<br>var<br>&nbsp; i: Integer;<br>begin<br>&nbsp; Result:=False;<br>&nbsp; for i:=1 to Top-1 do<br>&nbsp; &nbsp; if Stack[Top]=Stack then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result:=True;<br>&nbsp; &nbsp; &nbsp; Exit<br>&nbsp; &nbsp; end<br>end;<br><br>begin<br>&nbsp; Top:=1;<br>&nbsp; Stack[Top]:=0;<br>&nbsp; while Top&gt;0 do<br>&nbsp; begin<br>&nbsp; &nbsp; while Stack[Top]&lt;15 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(Stack[Top]);<br>&nbsp; &nbsp; &nbsp; if not Double then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if Top=3 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s:=IntToStr(Stack[1]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i:=2 to 3 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s:=s+'*'+IntToStr(Stack);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Form1.ListBox1.Items.Append(s)<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inc(Top);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stack[Top]:=0<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Dec(Top)<br>&nbsp; end<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Hahaha<br>end;<br><br>end.<br>
 
LeeChange,你的方法不对的,我是从01*05*07*08*09*10*11*13*18*24*35*45*68*69*78<br>中选3的全排列,不是排出1*2*3,1*2*4,1*2*5这中结果,2,3,4在数列中是没有的
 
这里已有解答,就是LeeChange的方法,借花献佛,不好意思了!<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1853152
 
把<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s:=IntToStr(Stack[1]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for i:=2 to 3 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s:=s+'*'+IntToStr(Stack);<br>改成<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s:=IntToStr(a[Stack[1]]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for i:=2 to 3 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s:=s+'*'+IntToStr(a[Stack]);
 
Thank you !!!!!!!!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
870
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部