序列1212321234321234543212.....如何编程实现输入一整数n,输出该序列的第n项?(100分)

L

leolhc

Unregistered / Unconfirmed
GUEST, unregistred user!
序列1212321234321234543212.....如何编程实现输入一整数n,输出该序列的第n项?
我猜想序列是下面这样得到的:
输入1得到序列1
输入2得到序列121
输入3得到序列1212321
......
但实在没编程的思路,不知道如何把n转化为序列,请各位大大提个醒,谢谢!
 
问题解决
procedure TForm1.printN2(n: integer);
var i:integer;
begin
if n=1 then
edit1.Text:=edit1.Text+inttostr(n)
else
begin
printN2(n-1);
for i:=2 to ndo
edit1.Text:=edit1.Text+inttostr(i);
for i:=n-1do
wnto 1do
edit1.Text:=edit1.Text+inttostr(i);
end;
end;
 
我认为序列应该是这样的:
12
123 2
1234 32
12345 432
...
那么程序就简单了:
function GetN(N: Integer): string;
var
I:Integer;
begin
Result := '';
if (N < 2) or (N >= 10) then
Exit;
SetLength(Result, N + N - 2);
for I := 1 to Ndo
Result := Char(I + ord('1') - 1);
//
for I := N + 1 to N + N - 2do
Result := Char(N - (I - N - 1) + ord('1') - 2);
end;
//////////////////
10以上的规律部清楚
 
解决了怎么办,问点问题,还是潇洒的直接放分?
 
呵呵,分乃身外物!参与了就有分,有去思考的分自然多一点。[:)]
 

Similar threads

D
回复
0
查看
749
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部