program FiboSearch;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
n=12;
type
TSpysok=array[1..n] of integer;
Var
K,i:integer;
a:TSpysok;
error:boolean;
procedure Vvid(var z:TSpysok);
var
sign,i,choice:integer;
begin
Randomize;
writeln('1 - Vypadkovi chysla');
writeln('2 - Vvesty chysla');
readln(choice);
while (choice<>1) and (choice<>2) do begin
writeln('!!! Nevirnyj vybir. Vvedit'' 1 abo 2');
readln(choice);
end;
if choice=1 then begin
sign:=1;
for i:=1 to n do begin
a[i]:=Random(1000)*sign;
sign:=-sign;
end;
end
else if choice=2 then begin
writeln('Vvedit'' 12 chysel');
for i:=1 to n do readln(a[i])
end
end;
procedure Sort(var z:TSpysok);
var
i,j,x:integer;
begin
for i:=n downto 2 do
for j:=1 to i-1 do
if a[j]>a[j+1] then begin
x:=a[j+1];
a[j+1]:=a[j];
a[j]:=x
end
end;
function Find(z:TSpysok; x:integer):integer;
var i,p,q,p1:integer;
found:boolean;
begin
Find:=0;
error:=false;
found:=false;
i:=8; p:=5; q:=3;
repeat
if x<a[i]
then
if q<>0 then begin
i:=i-q;
p1:=p;
p:=q; q:=p1-q
end
else begin
writeln('ERROR: Nema takogo elementa v masyvi.');
readln;
halt
end
else
if x>a[i] then
if p<>1 then begin
i:=i+q;
p:=p-q; q:=q-p
end
else begin
writeln('ERROR: Nema takogo elementa v masyvi.');
readln;
halt
end
else begin
Find:=i;
found:=true
end
until found;
end;
begin
writeln('*** Poshuk Fibonacci ***');
Vvid(a); Sort(a);
writeln(' Vhidna poslidovnist''');
for i:=1 to n do writeln(i,') ',a[i]);
write('Vvedit'' element, jakyy treba znaity:');
readln(K);
writeln('Poriadkovyi nomer chysla ',K,': ',Find(a,K));
readln
end.