有7个不同的数字,怎样输出N(N≤7)个不同组合的加法算式?一条式子中不允许同时出现2个一样的数字。如:不能出现A+A这样的式子。
解决方案 »
- 求助各位Csdner,谁能找出bug原因???
- MediaPlayer1
- ASP和DELPHI版的AES加解密算法互解~~~
- 200分求经纬度BL换算到高斯平面直角坐标XY(高斯投影正反算)的源码
- 不是处男了,庆祝!! 散分。大家来捧捧场。
- 打印控制高手请进来看看!!!!!!!!
- 拖动ScrollBox的滚动条时其中的TGraphicControl子类作的图会乱掉!帮忙,up有分!
- 高分!! 求Tidudpserver及tidudpclient使用方法,应用例子!!!
- [附代码]只运行一个实例,如果我的程序在系统托盘里,不能把FORM显示出来呢?谢谢指点^_^
- 用何用DELPHI可以实现选择SQL SERVER里的表?
- 在DELPHI中如何实现获取PARADOX表结构定义的列表?
- 各位,找一个用华表(CELL)做报表设计器
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
h,i,j,k,l,m,n:integer;
begin
for h:=1 to 7 do
begin
memo1.Lines.Add(inttostr(h));
for i:=h+1 to 7 do
begin
memo1.Lines.Add(inttostr(h)+'+'+inttostr(i));
for j:=i+1 to 7 do
begin
memo1.Lines.Add(inttostr(h)+'+'+inttostr(i)+'+'+inttostr(j));
for k:=j+1 to 7 do
begin
memo1.Lines.Add(inttostr(h)+'+'+inttostr(i)+'+'+inttostr(j)+'+'+inttostr(k));
for l:=k+1 to 7 do
begin
memo1.Lines.Add(inttostr(h)+'+'+inttostr(i)+'+'+inttostr(j)+'+'+inttostr(k)+'+'+inttostr(l));
for m:=l+1 to 7 do
memo1.Lines.Add(inttostr(h)+'+'+inttostr(i)+'+'+inttostr(j)+'+'+inttostr(k)+'+'+inttostr(l)+'+'+inttostr(m));
end;
end;
end;
end;
end;
end;end.
float a[7];
a[i]....
for(i=0;i<7;++i)
a[i]+a[i+1]
Windows, Messages, Variants, Classes, Graphics, Controls, Forms,
Dialogs,SysUtils,strutils, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
myarray:array[1..792]of string; //保存结果
index:integer;//记数器的功能
implementation
{$R *.dfm}
procedure liechu(n:string);
var j,k:integer;
v:char;
begin
for k:=1 to length(n) do
begin
v:=n[k];
j:=k;
while(j<>1)and(n[j-1]<v) do
begin
n[j]:=n[j-1];
j:=j-1;
end;
n[j]:=v;
end;
if not ansimatchstr(n,myarray) then
begin
index:=index+1; //记录计数
myarray[index]:=n;
end;
end;
procedure list(Full: String; Result: String; Max: Integer);
//Full:等待排列的总串;result:符合条件的串 MAX:总串的长度
var
I: Integer;
begin
if Length(Result) = Max then
begin
liechu(Result); //保存结果
Exit;
end;
for I := 1 to Length(Full) do
begin
if Pos(Full[I], Result) = 0 then //如果子串中没有该元素
list(Full, Result + Full[I], Max);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I,j: Integer;
S: String;
begin
index:=0;
for J:=1 to 7 do
begin
index:=0;
for i:=1 to 792 do
myarray[i]:='';
S := 'abcdefg';
List(S, '', j);
for i:=1 to index do
memo1.Lines.Add(myarray[i]) ;
end;
end;
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function getnum(m:integer;n:integer):integer;stdcall;
var
i,j,k:integer;
b:array [0..100] of integer;
s:string;
begin
k:=0;
for i:=1 to n do b[i]:=i;
b[0]:=-1;
while b[0]<0 do
begin
s:='';
j:=n;
inc(k);
while b[j]=m-n+j do j:=j-1;
b[j]:=b[j]+1;
for i:=j+1 to n do b[i]:=b[i-1]+1;
for i:=1 to n do
begin
if i>1 then
s:=s+' + '+inttostr(b[i])
else
s:=s+inttostr(b[i]);
end;
form1.memo1.Lines.Add(s);
end;
result:=k;//个数
end;
procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
count:integer;
begin
count:=0;
for i:=1 to 7 do
count:=count+getnum(7,i);
memo1.Lines.Add('总的个数为: '+inttostr(count)) ;
end;end.