L
lixianxiang
Unregistered / Unconfirmed
GUEST, unregistred user!
有个面试题:输入一个数字串,取得重复的数字,要求只能用一个循环。例如输入 1234534789 则得到 34; 输入32103190 则得到310。如果允许用多个循环的话倒是挺简单,但是面试人员要求只能用一个循环。寻求算法function Pvt_GetDuplicateNum(ANumStr: string): string;var Lv_i, Lv_j: Integer;
begin
for Lv_i := 1 to Length(ANumStr) do
begin
for Lv_j := Lv_i + 1 to Length(ANumStr) do
begin
if (ANumStr[Lv_i] = ANumStr[Lv_j]) and (Pos(ANumStr[Lv_i], Result) = 0)then
begin
Result := Result + ANumStr[Lv_i];
end;
end;
end;
end;
begin
for Lv_i := 1 to Length(ANumStr) do
begin
for Lv_j := Lv_i + 1 to Length(ANumStr) do
begin
if (ANumStr[Lv_i] = ANumStr[Lv_j]) and (Pos(ANumStr[Lv_i], Result) = 0)then
begin
Result := Result + ANumStr[Lv_i];
end;
end;
end;
end;