Skip to main content
Rollback to Revision 3
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
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.

program YellowPages;

type 
  string7 = String[7];
  data = Record
    namedata : shortstring;
    numberdata : string7;
  end;

var
  yellowpages : Array of data;
  searcharray : Array of string7;
  input, name, search : shortstring;
  number : string7;
  n, q, iter1 : word;

procedure SplitInput(input : shortstring; var name : shortstring; var number : string7);
var 
  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
  min := 0;
  max := high(target);
  while max >= min do
  begin
    median := (min + max) div 2;
    if target[median].namedata < search then low := median + 1
    else if target[median].namedata > search then high := median - 1
    else 
    begin
      BinarySearch := target[median].numberdata;
      break;
    end;
  end;
end;

begin
  readln(n, q);
  setlength(yellowpages, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    yellowpages[iter1].namedata := name;
    yellowpages[iter1].numberdata := number;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    searcharray[iter1] := BinarySearch(search, yellowpages);
  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.

program YellowPages;

type string7 = String[7];

var
  namearray : Array of 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 := '';
  number := '';
  for iter_proc := 1 to length(input) do
  begin
    if iter_proc < hitspace then name := name + input[iter_proc];
    if iter_proc > hitspace then number := number + input[iter_proc];
  end;
end;

begin
  readln(n, q);
  setlength(namearray, n);
  setlength(numberarray, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    namearray[iter1] := name;
    numberarray[iter1] := numberarray;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    for iter2 := 0 to (n - 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.
added 445 characters in body
Source Link
program YellowPages;

type 
  string7 = String[7];
  data = Record
    namedata : shortstring;
    numberdata : string7;
  end;

var
  yellowpages : Array of data;
  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 
  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
  min := 0;
  max := high(target);
  while max >= min do
  begin
    median := (min + max) div 2;
    if target[median].namedata < search then low := median + 1
    else if target[median].namedata > search then high := median - 1
    else 
    begin
      BinarySearch := target[median].numberdata;
      break;
    end;
  end;
end;

begin
  readln(n, q);
  setlength(yellowpages, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    yellowpages[iter1].namedata := name;
    yellowpages[iter1].numberdata := number;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    for iter2searcharray[iter1] := 0 to BinarySearch(n - 1) do
    begin
      if yellowpages[iter2].namedata = search then break;
    end;
    searcharray[iter1] :=, yellowpages[iter2].numberdata;yellowpages);
  end;
  for iter1 := 0 to (q - 1) do
  begin
    writeln(searcharray[iter1]);
  end;
end.

Improvement 1Improvements

Used Array of Records instead of parallel arrays.

Used binary search instead of linear search.

program YellowPages;

type 
  string7 = String[7];
  data = Record
    namedata : shortstring;
    numberdata : string7;
  end;

var
  yellowpages : Array of data;
  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 
  hitspace : byte;
begin
  hitspace := pos(' ', input);
  name := Copy(input, 1, hitspace - 1);
  number := Copy(input, hitspace + 1, length(shortstring));
end;

begin
  readln(n, q);
  setlength(yellowpages, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    yellowpages[iter1].namedata := name;
    yellowpages[iter1].numberdata := number;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    for iter2 := 0 to (n - 1) do
    begin
      if yellowpages[iter2].namedata = search then break;
    end;
    searcharray[iter1] := yellowpages[iter2].numberdata;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    writeln(searcharray[iter1]);
  end;
end.

Improvement 1

Used Array of Records instead of parallel arrays.

program YellowPages;

type 
  string7 = String[7];
  data = Record
    namedata : shortstring;
    numberdata : string7;
  end;

var
  yellowpages : Array of data;
  searcharray : Array of string7;
  input, name, search : shortstring;
  number : string7;
  n, q, iter1 : word;

procedure SplitInput(input : shortstring; var name : shortstring; var number : string7);
var 
  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
  min := 0;
  max := high(target);
  while max >= min do
  begin
    median := (min + max) div 2;
    if target[median].namedata < search then low := median + 1
    else if target[median].namedata > search then high := median - 1
    else 
    begin
      BinarySearch := target[median].numberdata;
      break;
    end;
  end;
end;

begin
  readln(n, q);
  setlength(yellowpages, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    yellowpages[iter1].namedata := name;
    yellowpages[iter1].numberdata := number;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    searcharray[iter1] := BinarySearch(search, yellowpages);
  end;
  for iter1 := 0 to (q - 1) do
  begin
    writeln(searcharray[iter1]);
  end;
end.

Improvements

Used Array of Records instead of parallel arrays.

Used binary search instead of linear search.

deleted 66 characters in body
Source Link
program YellowPages;

type 
  string7 = String[7];
  data = Record
    namedata : shortstring;
    numberdata : string7;
  end;

var
  namearrayyellowpages : Array of shortstring;data;
  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 
  hitspace : byte;
begin
  hitspace := pos(' ', input);
  name := Copy(input, 1, hitspace - 1);
  number := Copy(input, hitspace + 1, length(shortstring));
end;

begin
  readln(n, q);
  setlength(namearray, n);
  setlength(numberarrayyellowpages, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    namearray[iter1]yellowpages[iter1].namedata := name;
    numberarray[iter1]yellowpages[iter1].numberdata := numberarray;number;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    for iter2 := 0 to (n - 1) do
    begin
      if namearray[iter2]yellowpages[iter2].namedata = search then break;
    end;
    searcharray[iter1] := numberarray[iter2];yellowpages[iter2].numberdata;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    writeln(searcharray[iter1]);
  end;
end.

Improvement 1 : 

Changed SplitInput() body to use Copy() instead of manual copy.

Used Array of Records instead of parallel arrays.

program YellowPages;

type string7 = String[7];

var
  namearray : Array of 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 
  hitspace : byte;
begin
  hitspace := pos(' ', input);
  name := Copy(input, 1, hitspace - 1);
  number := Copy(input, hitspace + 1, length(shortstring));
end;

begin
  readln(n, q);
  setlength(namearray, n);
  setlength(numberarray, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    namearray[iter1] := name;
    numberarray[iter1] := numberarray;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    for iter2 := 0 to (n - 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.

Improvement 1 : Changed SplitInput() body to use Copy() instead of manual copy.

program YellowPages;

type 
  string7 = String[7];
  data = Record
    namedata : shortstring;
    numberdata : string7;
  end;

var
  yellowpages : Array of data;
  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 
  hitspace : byte;
begin
  hitspace := pos(' ', input);
  name := Copy(input, 1, hitspace - 1);
  number := Copy(input, hitspace + 1, length(shortstring));
end;

begin
  readln(n, q);
  setlength(yellowpages, n);
  setlength(searcharray, q);
  for iter1 := 0 to (n - 1) do
  begin
    readln(input);
    SplitInput(input, name, number);
    yellowpages[iter1].namedata := name;
    yellowpages[iter1].numberdata := number;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    readln(search);
    for iter2 := 0 to (n - 1) do
    begin
      if yellowpages[iter2].namedata = search then break;
    end;
    searcharray[iter1] := yellowpages[iter2].numberdata;
  end;
  for iter1 := 0 to (q - 1) do
  begin
    writeln(searcharray[iter1]);
  end;
end.

Improvement 1 

Changed SplitInput() body to use Copy() instead of manual copy.

Used Array of Records instead of parallel arrays.

deleted 66 characters in body
Source Link
Loading
deleted 85 characters in body
Source Link
Loading
added 99 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Loading
Source Link
Loading