Показать сообщение отдельно
  #8  
Старый 13.07.2009, 21:42
Аватар для pesi
pesi pesi вне форума
Активный
 
Регистрация: 12.09.2008
Сообщения: 275
Репутация: 43
По умолчанию

попробуй так, только тут подбор до 4 символов

Код:
function number1(const S:string):string;
var
i:integer;
str:string;
begin
 str := '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 Result:='';
 for i:=1 to Length(str) do
  if str[i] = s  then
   begin
    Result:=str[i];
    exit;
   end;
end;

//111111111111111111111111111111111111111111111111111111111111111111111111111111

function number2(const S:string):string;
var
i1, i2:integer;
str:string;
bol:boolean;
begin
 bol:=false;
 str := '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 Result:='';

 for i1:=1 to Length(str) do
  if str[i1] = s  then
   begin
    bol:=true;
    Result:=str[i1];
    exit;
   end;

if bol=false then
 begin
  for i1:=1 to Length(str) do
  for i2:=1 to Length(str) do
   if str[i1]+str[i2] = s  then
    begin
     Result:=str[i1]+str[i2];
     exit;
    end;
end;
end;

//2222222222222222222222222222222222222222222222222222222222222222222222222222222

function number3(const S:string):string;
var
i1, i2, i3, u :integer;
str :string;
bol:boolean;
begin
 bol:=false;
 str := '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 Result:='';
 u:=Length(str);

for i1:=1 to u do
  if str[i1] = s  then
   begin
    bol:=true;
    Result:=str[i1];
    exit;
   end;
if bol=false then
 begin
  for i1:=1 to u do
  for i2:=1 to u do
   if str[i1]+str[i2] = s  then
    begin
     bol:=true;
     Result:=str[i1]+str[i2];
     exit;
    end;
end;

if bol=false then
 begin
 for i1:=1 to u do
  for i2:=1 to u do
  for i3:=1 to u do
  begin
   if str[i1]+str[i2]+str[i3] = s  then
    begin
     Result:=str[i1]+str[i2]+str[i3];
     exit;
    end;
  end;
end;
end;

//33333333333333333333333333333333333333333333333333333333333333333333333333333333333333

function number4(const S:string):string;
var
i1, i2, i3, i4, u :integer;
str :string;
bol:boolean;
begin
 bol:=false;
 str := '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 Result:='';
 u:=Length(str);

for i1:=1 to u do
  if str[i1] = s  then
   begin
    bol:=true;
    Result:=str[i1];
    exit;
   end;

if bol=false then
 begin
  for i1:=1 to u do
  for i2:=1 to u do
   if str[i1]+str[i2] = s  then
    begin
     bol:=true;
     Result:=str[i1]+str[i2];
     exit;
    end;
end;

if bol=false then
 begin
 for i1:=1 to u do
  for i2:=1 to u do
  for i3:=1 to u do
  begin
   if str[i1]+str[i2]+str[i3] = s  then
    begin
     bol:=true;
     Result:=str[i1]+str[i2]+str[i3];
     exit;
    end;
  end;
end;

if bol=false then
 begin
 for i1:=1 to u do
  for i2:=1 to u do
  for i3:=1 to u do
   for i4:=1 to u do
  begin
   if str[i1]+str[i2]+str[i3]+str[i4] = s  then
    begin
     Result:=str[i1]+str[i2]+str[i3]+str[i4];
     exit;
    end;
  end;
end;
end;

//4444444444444444444444444444444444444444444444444444444444444444444444444444444

procedure TForm1.Button1Click(Sender: TObject);
begin
edit3.Clear;

 if strtoint(edit2.Text)= 1 then
  edit3.Text:=number1(edit1.Text) else

 if strtoint(edit2.Text)= 2 then
  edit3.Text:=number2(edit1.Text) else

 if strtoint(edit2.Text)= 3 then
  edit3.Text:=number3(edit1.Text) else

 if strtoint(edit2.Text)= 4 then
  edit3.Text:=number4(edit1.Text)

end;
Ответить с цитированием