Advertisement
Guest User

Untitled

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