Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

TIPS_1_laba / program / Unit1

.pas
Скачиваний:
27
Добавлен:
04.06.2015
Размер:
7.93 Кб
Скачать
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Math, Buttons, TeeProcs, TeEngine, Chart,
MXGRAPH, Series, Menus;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
RadioGroup1: TRadioGroup;
Button3: TButton;
ComboBox1: TComboBox;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Chart1: TChart;
Series1: TLineSeries;
MainMenu1: TMainMenu;
N1: TMenuItem;
Series2: TLineSeries;
Series3: TLineSeries;
Series4: TLineSeries;
procedure Button3Click(Sender: TObject);
procedure N1Click(Sender: TObject);


private
{ Private declarations }
public
{ Public declarations }
end;

var
I,Code,Pair,LenStr,k,z,fnd,orig:integer; a,b,fake:array of string; s:string;
Form1: TForm1;


implementation

{$R *.dfm}
{$MAXSTACKSIZE 1147483646}

function Pryamoe(strn:string):string;
var str1,str2:string;
ch1,ch2:char;
begin
lenstr:=length(strn);
//преобразование прямым правилом: первый в начало
str1:=strn;
str2:=strn;
ch1:=str1[pair];
delete (str2,pair,1);
insert (ch1, str2,1);
//преобразование прямым правилом: последний в конец
ch2:=str1[pair+1];
delete (str2,pair+1,1);
insert (ch2, str2,lenstr);
result:=str2;
end;

function Obratnoe(strn:string):string;
var str1,str2:string;
ch1,ch2:char;
begin
lenstr:=length(strn);
//преобразование обратным правилом: первый в конец
str1:=strn;
str2:=strn;
ch1:=str1[pair];
delete (str2,pair,1);
insert (ch1, str2,lenstr);
//преобразование обратным правилом: последний в начало
ch2:=str1[pair+1];
delete (str2,pair,1);
insert (ch2, str2,1);
result:=str2;
end;

function poisk(a:array of string;rez:string):boolean;
var i:integer;
begin
for i:=0 to length(a)-1 do
if a[i]=rez then
begin
result:=true;
exit;
end
else result:=false;
end;

function fact(n:integer):integer;
begin
result:=1;
for i:=1 to n do
result:=result*i;
end;

procedure original(a:array of string);
var j,t:integer;
begin
with form1 do begin
t:=0;
for i:=0 to length(a)-1 do begin
for j:=length(b)-1 downto 0 do
if a[i]=b[j] then
begin
inc(t);
end;
if t=0 then
begin
setlength(b,length(b)+1);
b[length(b)-1]:=a[i];
end
else t:=0;
end;
end;
end;

procedure luch;
begin
k:=0;
with form1 do begin
setlength(a,1);
a[0]:=edit1.text;
repeat
if combobox1.ItemIndex=0 then
begin
pair:=random(length(s)-1)+1;
a[0]:=pryamoe(a[0]);
k:=k+1;
end;
if combobox1.ItemIndex=1 then
begin
pair:=random(length(s)-1)+1;
a[0]:=obratnoe(a[0]);
k:=k+1;
end;
if edit2.text=a[0] then
begin
inc(fnd);
exit;
end
else original(a);
until length(b)=orig;
end;
end;

procedure glub;
var newind:integer; temp:string;
begin
with form1 do
begin
setlength(a,length(s)-1);
if combobox1.ItemIndex=0 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=pryamoe(s);
end;
if combobox1.itemindex=1 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=obratnoe(s);
end;
k:=1;
if poisk(a,edit2.Text) then
begin
inc(fnd);
exit;
end
else
original(a);
if length(b)=orig then exit;
repeat
newind:=random(length(s)-1);
temp:=a[newind];
if combobox1.itemindex=0 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=pryamoe(temp);
end;
if combobox1.itemindex=1 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=obratnoe(temp);
end;
k:=k+1;

if poisk(a,edit2.Text) then
begin
inc(fnd);
exit;
end
else original(a);
until (orig=length(b));


//until (k=length(s)) or poisk(a,edit2.text);
inc(fnd);
if not poisk(a,edit2.Text) then dec(fnd);
end;
end;

procedure shir;
var j:integer;
begin
with form1 do
begin
setlength(a,length(s)-1);
if combobox1.itemindex=0 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=pryamoe(s);
end;
if combobox1.itemindex=1 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=obratnoe(s);
end;
k:=1;
if poisk(a,edit2.Text) then inc(fnd)
else
//original(a);
//if length(b)=orig then exit;
repeat
fake:=copy(a);
setlength(a,length(a)*(length(s)-1));
i:=0;
if combobox1.ItemIndex=0 then
while i<=length(a)-1 do
for j:=0 to length(s)-2 do
begin
pair:=0;
repeat
inc(pair);
a[i]:=pryamoe(fake[j]);
inc(i);
until pair=length(s)-1;
end;
if combobox1.ItemIndex=1 then
while i<=length(a)-1 do
for j:=0 to length(s)-2 do
begin
pair:=0;
repeat
inc(pair);
a[i]:=obratnoe(fake[j]);
inc(i);
until pair=length(s)-1;
end;
k:=k+1;
//else original(a);
until (k=length(s)) or poisk(a,edit2.text);
//until (orig=length(b));
inc(fnd);
if not poisk(a,edit2.Text) then dec(fnd);
end;
end;

procedure paral;
var j:integer;
begin
with form1 do
begin
setlength(a,length(s)-1);
if combobox1.itemindex=0 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=pryamoe(s);
end;
if combobox1.itemindex=1 then
for i:=0 to length(s)-2 do
begin
pair:=i+1;
a[i]:=obratnoe(s);
end;
k:=1;
if poisk(a,edit2.Text) then
begin
inc(fnd);
exit;
end
else
original(a);
if length(b)=orig then exit;
repeat
i:=0;
fake:=copy(a);
pair:=random(length(s)-1)+1;
if combobox1.ItemIndex=0 then
while i<=length(a)-1 do
for j:=0 to length(s)-2 do
begin
a[i]:=pryamoe(fake[j]);
inc(i);
end;
if combobox1.ItemIndex=1 then
while i<=length(a)-1 do
for j:=0 to length(s)-2 do
begin
a[i]:=obratnoe(fake[j]);
inc(i);
end;
k:=k+1;
if poisk(a,edit2.Text) then
begin
inc(fnd);
exit;
end
else original(a);
//until poisk(a,edit2.text);
until (orig=length(b));
inc(fnd);
if not poisk(a,edit2.Text) then dec(fnd);
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var sumITER:integer; sredITER:real;
begin
sumITER:=0;
fnd:=0;
randomize;
s:=edit1.Text;
if length(s) mod 2 =0 then
if combobox1.ItemIndex=0 then orig:=round(fact(length(s))/2)
else orig:=fact(length(s));
if length(s) mod 2<>0 then
if combobox1.ItemIndex=0 then orig:=fact(length(s))
else orig:=round(fact(length(s))/2);
if radiogroup1.ItemIndex=2 then
begin
shir;
sumITER:=k*100;
fnd:=fnd*100;
end
else
for z:=1 to 100 do
begin
setlength(b,1);
b[0]:=s;
if radiogroup1.ItemIndex=0 then luch;
if radiogroup1.ItemIndex=1 then glub;
if radiogroup1.ItemIndex=3 then paral;
sumITER:=sumITER+k;
end;
sredITER:=sumITER/100;
label4.Caption:=inttostr(round(sredITER));
label7.Caption:=inttostr(fnd);
if radiogroup1.ItemIndex=0 then series1.AddXY(length(s),sredITER);
if radiogroup1.ItemIndex=1 then series2.AddXY(length(s),sredITER);
if radiogroup1.ItemIndex=2 then series3.AddXY(length(s),sredITER);
if radiogroup1.ItemIndex=3 then series4.AddXY(length(s),sredITER);
end;

procedure TForm1.N1Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
label4.Caption:='';
label7.Caption:='';
end;

end.
Соседние файлы в папке program
  • #
    04.06.2015876 б27Project1.res
  • #
    04.06.20159 Кб27Unit1.$$$
  • #
    04.06.201513.77 Кб27Unit1.dcu
  • #
    04.06.201551 б27Unit1.ddp
  • #
    04.06.20156.4 Кб27Unit1.dfm
  • #
    04.06.20157.93 Кб27Unit1.pas
  • #
    04.06.201551 б27Unit1.~ddp
  • #
    04.06.20156.4 Кб27Unit1.~dfm
  • #
    04.06.20157.93 Кб27Unit1.~pas