Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.59 KB | None | 0 0
  1.  
  2. program begin12;
  3.  
  4. {$APPTYPE CONSOLE}
  5.  
  6. uses
  7.   SysUtils;
  8.  
  9. const n = 10;
  10.  
  11. type tzap = Record
  12.    p1:Integer;
  13.    p2:string[15];
  14.    p3:Boolean;
  15. end;
  16.    //  ìàññèâû , ïîòîì ñïèñêè 2 ëàáà ,ê ñëåä ëàáîðàòîðíîé -  ìåíþ , ïðîöåäóðà ÷òåíèå èç ôàéëà,
  17.    //  çàïèñü ôàéë òèïèçèðîâàííûé , äîáàâëåíèå , ðåäàêòèðîâàíèå , ïîèñê  + ïðîñìîòð
  18.  
  19. type tmas = array [1..n] of tzap;
  20.  
  21.  
  22.  
  23. procedure input_mas(var a:tmas);
  24.  var i:integer; k:string;
  25. begin
  26.   Randomize;
  27.   for i:=1 to n do
  28.    with a[i] do
  29.     begin
  30.        p1:=Random(201);
  31.        Str(i,k);
  32.        p2:='my_test' + k;
  33.        p3:=false;
  34.     end;
  35. end;
  36.  
  37. procedure output_mas(var a:tmas);
  38.  var i:integer;
  39. begin
  40.   for i:=1 to n do
  41.   with a[i] do
  42.    begin
  43.     write(p1:5,' ');
  44.     write(p2:18,' ');
  45.     write(p3,' ');
  46.     writeln;
  47.    end;
  48. end;
  49.  
  50. procedure sortpsecond (var a:tmas);
  51. var i,j:integer; tmp:tzap;
  52.  
  53. begin
  54.   for i:=1 to n-1 do
  55.    begin
  56.     for j:=1 to n-i do
  57.      begin
  58.        if a[j].p2>a[j+1].p2 then
  59.         begin
  60.           tmp:=a[j];
  61.           a[j]:=a[j+1];
  62.           a[j+1]:=tmp;
  63.         end;
  64.      end;
  65.    end;
  66. end;
  67.  
  68. procedure binarysearch (var a:tmas);
  69. var s1:string; i,m,j,r,c:integer; flag:Boolean;
  70. begin
  71.  readln(s1);
  72.  m:=n div 2;
  73.  i:=1;
  74.  j:=m;
  75.  r:=n;
  76.   if a[j].p2=s1 then
  77.      a[j].p3:=True;
  78.    flag:=False;
  79.    while (i<=n) and (not flag)  do
  80.    begin
  81.      if a[i].p2=s1 then
  82.      flag:=true;
  83.      Inc(i);
  84.    end;
  85.    Dec(i);
  86.    if not flag then Writeln('Incorrect input') else
  87.   while (s1<>a[j].p2)     do
  88.   begin
  89.     a[j].p3:=True;
  90.     if a[j].p2<s1 then
  91.      begin
  92.       i:=j+1;
  93.       j:=(i+r) div 2 ;
  94.      end;
  95.     if a[j].p2>s1 then
  96.      begin
  97.       r:=j-1;
  98.       j:=(i+r) div 2;
  99.      end;
  100.     if a[j].p2=s1 then
  101.      a[j].p3:=true;
  102.  
  103.  
  104.   end;
  105. end;
  106.  
  107.  
  108.  
  109. procedure truel (var a:tmas);
  110. var j,count:integer;
  111. begin
  112.   for j:=1 to n do
  113.   if a[j].p3=True then
  114.    inc(count);
  115.   Writeln('Number of true elements = ' , count);
  116. end;
  117.  
  118. procedure falseel(var a:tmas);
  119. var j:integer;
  120. begin
  121.   for j:=1 to n do
  122.    a[j].p3:=false;
  123. end;
  124.  
  125. procedure binarysearch2 (var a:tmas);
  126. var  i,m,j,num,r,s,zapel:integer;  flag2:boolean;
  127. begin
  128.  read(num);
  129.  m:=n div 2;
  130.  i:=1;
  131.  j:=m;
  132.  r:=n;
  133.  if a[j].p1=num then
  134.       a[j].p3:=True;
  135.  flag2:=False;
  136.    while (i<=n) and (not flag2)  do
  137.    begin
  138.      if a[i].p1=num then
  139.      flag2:=true;
  140.      Inc(i);
  141.    end;
  142.    Dec(i);
  143.    if not flag2 then Writeln('Incorrect input') else
  144.  while (num<>a[j].p1)  do
  145.   begin
  146.     a[j].p3:=true;
  147.     if num>a[j].p1 then
  148.      begin
  149.        i:=j+1;
  150.        j:=(i+r) div 2;
  151.      end;
  152.     if num<a[j].p1 then
  153.      begin
  154.        r:=j-1;
  155.        j:=(i+r) div 2;
  156.      end;
  157.     if num=a[j].p1 then
  158.      a[j].p3:=true;
  159.   end;
  160.  
  161.  s:=j;
  162.  zapel:=j;
  163.  repeat
  164.    Dec(s);
  165.    if a[s].p1=a[zapel].p1 then
  166.    a[s].p3:=True;
  167.  until s=1;
  168.  repeat
  169.    inc(j);
  170.    if a[j].p1=a[zapel].p1 then
  171.    a[j].p3:=true;
  172.  until j=n;
  173.  
  174. end;
  175.  
  176. procedure sortpione(var a:tmas);
  177. var i,j:integer; tmp:tzap;
  178. begin
  179.  for i:=1 to n-1 do
  180.   begin
  181.      for j:=1 to n-i do
  182.       begin
  183.        if a[j].p1>a[j+1].p1 then
  184.         begin
  185.           tmp:=a[j];
  186.           a[j]:=a[j+1];
  187.           a[j+1]:=tmp;
  188.         end;
  189.       end;
  190.   end;
  191. end;
  192. var a:tmas;
  193.  
  194. begin
  195.  input_mas(a);
  196.  output_mas(a);
  197.  sortpsecond(a);
  198.  writeln;
  199.  binarysearch(a);
  200.  output_mas(a);
  201.  Writeln;
  202.  truel(a);
  203.  sortpione(a);
  204.  falseel(a);
  205.  Writeln;
  206.  output_mas(a);
  207.  Writeln;
  208.  binarysearch2(a);
  209.  output_mas(a);
  210.  truel(a);
  211.  readln;
  212.  readln;
  213. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement