program YellowPages;
type
string7 = String[7];
data = Record
namedata : shortstring;
numberdata : string7;
end;
var
yellowpagesnamearray : Array of data;shortstring;
numberarray, searcharray : Array of string7;
input, name, search : shortstring;
number : string7;
n, q, iter1, iter2 : word;
procedure SplitInput(input : shortstring; var name : shortstring; var number : string7);
var
iter_proc, hitspace : byte;
begin
hitspace := pos(' ', input);
name := Copy(input, 1, hitspace - 1);'';
number := Copy(input, hitspace + 1, length(shortstring));
end;
function BinarySearch(search : shortstring; target : array of data): string7;
var'';
min, max, median : word;
begin
for miniter_proc := 0;
max1 :=to highlength(targetinput);
while max >= min do
begin
median := (min + max) div 2;
if target[median].namedataiter_proc < searchhitspace then lowname := medianname + 1input[iter_proc];
else if target[median].namedataiter_proc > searchhitspace then high := median - 1
else
begin
BinarySearchnumber := target[median].numberdata;
break;
number + end;input[iter_proc];
end;
end;
begin
readln(n, q);
setlength(yellowpagesnamearray, n);
setlength(numberarray, n);
setlength(searcharray, q);
for iter1 := 0 to (n - 1) do
begin
readln(input);
SplitInput(input, name, number);
yellowpages[iter1].namedatanamearray[iter1] := name;
yellowpages[iter1].numberdatanumberarray[iter1] := number;numberarray;
end;
for iter1 := 0 to (q - 1) do
begin
readln(search);
searcharray[iter1]for iter2 := BinarySearch0 to (search,n yellowpages- 1); do
begin
if namearray[iter2] = search then break;
end;
searcharray[iter1] := numberarray[iter2];
end;
for iter1 := 0 to (q - 1) do
begin
writeln(searcharray[iter1]);
end;
end.
Improvements
Changed SplitInput()
body to use Copy()
instead of manual copy.
Used Array of Records instead of parallel arrays.
Used binary search instead of linear search.