Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.25 KB | None | 0 0
  1. program Laba1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.   Var
  8.   N,k,h0,i : integer ;
  9.   x: array of integer;
  10.   h: array of integer;
  11.   Max,Xhmax:integer;
  12. procedure Input ;
  13. Var
  14.    ArrayLength: integer;
  15.    IsCorrect: boolean;
  16.  Begin
  17.    Repeat
  18.       Writeln('Please,enter N and H,where H is the hight of tower 0 and N is a quantity of towers. ');
  19.       Writeln('All the items must be integer');
  20.       IsCorrect:=False;
  21.       Try
  22.          Write('Tower 0 [N,h0]:');
  23.          Read(ArrayLength,h0);
  24.          SetLength(x,ArrayLength);
  25.          IsCorrect:=True;
  26.       Except
  27.          Writeln('Error.Try again');
  28.       End;
  29.    Until (IsCorrect) and (ArrayLength>0);
  30.    Repeat
  31.       Writeln('Please,enter x and h,where h is the hight of a tower and x is its situation');
  32.       Writeln('They  must be positive and integer');
  33.       IsCorrect:=False;
  34.       Try
  35.          For i := 1 to ArrayLength do
  36.          Begin
  37.             Write('x[',i,'],h[',i,']=');
  38.             Read (x[i],h[i]);
  39.             IsCorrect:=True;
  40.          End;
  41.       Except
  42.          Writeln ('Error. Try again');
  43.       End;
  44.    Until (IsCorrect) and (h[i] > 0) ;
  45.  End;
  46.  
  47. Function Maximum(Var  Max,Xhmax: integer): integer;
  48. Begin
  49.    Max := h[1];
  50.    Xhmax := x[1];
  51.    For i := 1 to N do
  52.       If h[i]> Max then
  53.       Begin
  54.          Max := h[i];
  55.          Xhmax := x[i];
  56.       End;
  57.  End ;
  58. Function Visability(k: integer): integer ;
  59. Begin
  60.    k:=0;
  61.    i:=1;
  62.    If h0 < Max then
  63.       While x[i] <= Xhmax do
  64.       Begin
  65.          If h[i] < h[i+1] then                     // consideration of overlaying situation
  66.              k:=k+1;
  67.          i:=i+1;
  68.       End;
  69.     If h0 > Max Then
  70.        While  x[i] <= x[N] do
  71.           Begin
  72.              If h[i] < h[i+1] then
  73.                 k:=k+1;
  74.              i:=i+1;
  75.           End;
  76.     if h0=Max Then
  77.        While x[i] <= x[N] do
  78.           Begin
  79.              If Max = h[i] then
  80.                 k:=k;
  81.              If Max <> h [i] then
  82.                 k:=k+1;
  83.              i:=i+1
  84.           End;
  85.     writeln('There are ',k,'towers which you can see from tower0');
  86.     readln;
  87. End;
  88. Procedure Main;
  89.    Begin
  90.    InPut;
  91.    Maximum(Max,Xhmax);
  92.    Visability(k);
  93.    End;
  94. Begin
  95.    Main;
  96. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement