Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program begin12;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const n = 15;
- type tzap = Record
- p1:Integer;
- p2:string[15];
- p3:Boolean;
- end;
- type tmas = array [1..n] of tzap;
- procedure input_mas(var a:tmas);
- var i:integer; k:string;
- begin
- Randomize;
- for i:=1 to n do
- with a[i] do
- begin
- p1:=Random(201);
- Str(i,k);
- p2:='my_test' + k;
- p3:=false;
- end;
- end;
- procedure output_mas(var a:tmas);
- var i:integer;
- begin
- for i:=1 to n do
- with a[i] do
- begin
- write(p1:5,' ');
- write(p2:18,' ');
- write(p3,' ');
- writeln;
- end;
- end;
- procedure sortpsecond (var a:tmas);
- var i,j:integer; tmp:tzap;
- begin
- for i:=1 to n-1 do
- begin
- for j:=1 to n-i do
- begin
- if a[j].p2>a[j+1].p2 then
- begin
- tmp:=a[j];
- a[j]:=a[j+1];
- a[j+1]:=tmp;
- end;
- end;
- end;
- end;
- procedure binarysearch (var a:tmas);
- var s1:string; i,m,j,r:integer;
- begin
- readln(s1);
- m:=n div 2;
- i:=1;
- j:=m;
- r:=n;
- if a[j].p2=s1 then
- a[j].p3:=True;
- while (s1<>a[j].p2) do
- begin
- a[j].p3:=True;
- if a[j].p2<s1 then
- begin
- i:=j+1;
- j:=(i+r) div 2 ;
- end;
- if a[j].p2>s1 then
- begin
- r:=j-1;
- j:=(i+r) div 2;
- end;
- if a[j].p2=s1 then
- a[j].p3:=true;
- end;
- end;
- procedure truel (var a:tmas);
- var j,count:integer;
- begin
- for j:=1 to n do
- if a[j].p3=True then
- inc(count);
- Writeln('Number of true elements = ' , count);
- end;
- procedure falseel(var a:tmas);
- var j:integer;
- begin
- for j:=1 to n do
- a[j].p3:=false;
- end;
- procedure binarysearch2 (var a:tmas);
- var i,m,j,num,r,s:integer;
- begin
- read(num);
- m:=n div 2;
- i:=1;
- j:=m;
- r:=n;
- if a[j].p1=num then
- a[j].p3:=True;
- while (num<>a[j].p1) do
- begin
- a[j].p3:=true;
- if num>a[j].p1 then
- begin
- i:=j+1;
- j:=(i+r) div 2;
- end;
- if num<a[j].p1 then
- begin
- r:=j-1;
- j:=(i+r) div 2;
- end;
- if num=a[j].p1 then
- a[j].p3:=true;
- end;
- s:=j;
- while a[s].p1=a[s-1].p1 do
- begin
- Dec(s);
- a[s].p3:=true;
- end;
- while a[j].p1=a[j+1].p1 do
- begin
- Inc(j);
- a[j].p3:=true;
- end;
- end;
- procedure sortpione(var a:tmas);
- var i,j:integer; tmp:tzap;
- begin
- for i:=1 to n-1 do
- begin
- for j:=1 to n-i do
- begin
- if a[j].p1>a[j+1].p1 then
- begin
- tmp:=a[j];
- a[j]:=a[j+1];
- a[j+1]:=tmp;
- end;
- end;
- end;
- end;
- var a:tmas;
- begin
- input_mas(a);
- output_mas(a);
- sortpsecond(a);
- writeln;
- binarysearch(a);
- output_mas(a);
- Writeln;
- truel(a);
- sortpione(a);
- falseel(a);
- Writeln;
- output_mas(a);
- Writeln;
- binarysearch2(a);
- output_mas(a);
- truel(a);
- readln;
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement