100分求一算法(100分)

C

cuteh

Unregistered / Unconfirmed
GUEST, unregistred user!
A: 1,2,3...
B: 1,2,3,4...
C: 1,2,3...
.
.
.

要求得出 A1B1...,A1B2...,A1B3...,A1B4...A2B1...
形式的所有组合,横向纵向都不确定

谢谢

 
A: 1,2,3...
B: 1,2,3,4...
C: 1,2,3...
.
.
.
这些数据程序如何获得?来自数据表,键盘输入,文本文件?
 
来源无关,可以自己定义任何类型

其实是来自数据库的,不过需要的算法是进入内存后的
 
问题还是不清楚
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

const
Rows = 3
//行数

procedure Hahaha;
var
Max: array [1..Rows] of Integer
//每行的可取值数目
i: Integer;
s: string;

Stack: array [1..Rows] of Integer;
Top: Integer;
begin
Max[1]:=3;
Max[2]:=4;
Max[3]:=3;

Top:=1;
Stack[Top]:=0;
while Top>0 do
begin
while Stack[Top]<Max[Top] do
begin
Inc(Stack[Top]);
if Top=Rows then
begin
s:='';
for i:=1 to Rows do
s:=s+Chr(Ord('A')-1+i)+IntToStr(Stack);
Form1.ListBox1.Items.Append(s);
Application.ProcessMessages
end
else
begin
Inc(Top);
Stack[Top]:=0;
end
end;
Dec(Top)
end
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Hahaha
end;

end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
934
DelphiTeacher的专栏
D
I
回复
0
查看
916
import
I
I
回复
0
查看
405
import
I
顶部