高分求解算法
我要产生从字符 ak 到 jac 之间的所有的字符
即 ak,al,am,an……az,
aaa,aab,aac…… aaz,
aba,abb,abb…… abz,
……
baa,bab,bac…… baz,
bba,bbb,bbc…… bbz,
……
……
jaa,jab,jac
应该用什么算法啊?谢谢各位,up者3分。分不够再加。
问题点数:143、回复次数:8Top
1 楼windindance(风舞轻扬·白首为功名)回复于 2002-01-16 17:59:43 得分 0
三重循环就可以。Top
2 楼jxzqsun(少年时代)回复于 2002-01-16 18:02:10 得分 0
你具体写出来,我测试通过了就给分。
呵呵,谢谢你了。Top
3 楼jxzqsun(少年时代)回复于 2002-01-16 18:03:37 得分 0
如果我要产生 ak 到 kdszdf 3重循环可以吗?Top
4 楼zswang(伴水清清)(专家门诊清洁工)回复于 2002-01-16 18:22:33 得分 143
function ZsLadder(mText: string; mLength: Integer = 0): string; { 阶梯 }
var
I, L: Integer;
S, T: string;
begin
Result := '';
L := Length(mText);
if L < 1 then Exit;
if mLength <= 0 then mLength := L;
S := '';
for I := 1 to mLength do S := S + mText[1]; //00000
T := '';
for I := 1 to mLength do T := T + mText[L]; //44444
while S <> T do begin
Result := Result + S + #13#10;
for I := mLength downto 1 do
if S[I] = mText[L] then
S[I] := mText[1]
else begin
S[I] := mText[Pos(S[I], mText) + 1];
Break;
end;
end;
Result := Result + S + #13#10;
end; { ZsLadder }
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
with TStringList.Create do try
Text := ZsLadder('abcdefghijklmnopqrstuvwxyz', 2);
Text := Text + ZsLadder('abcdefghijklmnopqrstuvwxyz', 3);
for I := Count - 1 downto IndexOf('jac') + 1 do Delete(I);
for I := IndexOf('ak') - 1 downto 0 do Delete(I);
RichEdit1.Text := Text;
finally
Free;
end;
end;
Top
5 楼windindance(风舞轻扬·白首为功名)回复于 2002-01-16 18:27:37 得分 0
那就是六重呀:)
for i:=0 to ord('j')-ord('a') do
for j:=0 to ord('z')-ord('a') do
for k:=-1 to ord('z')-ord('a') do
begin
if (i = ord('j') - ord('a') ) and ((j > 0) or (k>3) ) then
break;
write(chr(i+ord('a')),chr(j+ord('a')) );
if (k>=0) write(chr(k+ord('a')));
writeln;
end;Top
6 楼jxzqsun(少年时代)回复于 2002-01-16 18:31:10 得分 0
高手,另外,如果我要产生 ak 到 kdszdf 3该怎么做?呵呵。Top
7 楼zswang(伴水清清)(专家门诊清洁工)回复于 2002-01-16 18:38:15 得分 0
procedure TForm1.Button1Click(Sender: TObject);
begin
with TStringList.Create do try
Text := Text + ZsLadder('abcdefghijklmnopqrstuvwxyz', 1);
Text := Text + ZsLadder('abcdefghijklmnopqrstuvwxyz', 2);
Text := Text + ZsLadder('abcdefghijklmnopqrstuvwxyz', 3);
SaveToFile('C:\Temp.txt');
finally
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
I, B, E: Integer;
begin
with TStringList.Create do try
LoadFromFile('C:\Temp.txt');
B := IndexOf(Edit1.Text);
E := IndexOf(Edit2.Text);
for I := Count - 1 downto 0 do if (I > E) or (I < B) then Delete(I);
RichEdit1.Text := Text;
finally
Free;
end;
end;
Top
8 楼zswang(伴水清清)(专家门诊清洁工)回复于 2002-01-16 18:44:08 得分 0
Edit1.Text := IntToStr(26 * 26* 26* 26* 26* 26);//308915776308915776//!!!!!!Top




