practica 7 ejercicio 6
program HelloWorld;
const
flores = 8;
type
rangoFlores = 0 .. flores;
Tnombre = string [15];
Tvector = array [rangoFlores] of Tnombre;
procedure cargarVector(var v : Tvector);
var i:rangoFlores;
begin
for i:=1 to flores do begin
readln(v[i]);
end;
end;
procedure buscarFlores(v:Tvector;n:Tnombre;var pflor:rangoFlores;var m:boolean);
var
mid,ult,pri:rangoFlores;
begin
ult:=flores;
pri:=1;
mid:= (ult+pri)div 2;
while (v[mid] <> n) and not(m) do begin
mid:= (ult+pri)div 2;
if ((v[mid] > n)and(v[mid-1] < n))or((v[mid] < n)and(v[mid+1] > n)) or(v[ult] < n)or(v[pri] > n)then begin
m:=true;
end else
if v[mid] > n then begin
ult:=mid;
end else
if v[mid] < n then begin
pri:=mid;
end else
pflor:=mid;
end;
end;
var
s:rangoFlores;
v:Tvector;
f:Tnombre;
m:boolean;
begin
cargarVector(v);
readln(f);
m:=false;
buscarFlores(v,f,s,m);
if m then begin
writeln('la flor no existe');
end else writeln('la flor se encuentra en ',s);
end.
|
run
| edit
| history
| help
|
0
|
|
|