Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.70 KB | None | 0 0
  1. program Laba1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. Var
  9.   N,h0,i,k : 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) and (h0 > 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) and (x[i] > 0);
  46.     i:=0;
  47.  End;
  48. Procedure Maximum(Var  Max,Xhmax: 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.       i:=0;
  59.  End ;
  60. Procedure OutPut( k: integer) ;
  61. Begin
  62.    k:=0;
  63.    i:=1;
  64.    If h0 < Max then
  65.       While x[i] < Xhmax do
  66.       Begin
  67.          If h[i] < h[i+1] then { consideration of overlaying situation  }
  68.             k:=k+1;
  69.          i:=i+1;
  70.          If (h[i] < h[i-1]) and (h[i] < h[i+1]) then  { the situation of being between two towers }
  71.           k:=k;
  72.       End;
  73.     If h0 > Max Then
  74.       repeat
  75.          k:=k+1;
  76.          i:=i+1
  77.       until h[i] <= h[i+1] ;
  78.       While  x[i] <= x[N] do
  79.          Begin
  80.            If h[i] < h[i+1] then
  81.              k:=k+1;
  82.            If h[i]-h[i+1] > 5 then { When one tower is much bigger than the next one ,Its overlaying }
  83.               k:=k;
  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 {when two Max towers in a row are the same,its overlaying}
  90.                 k:=k+1;
  91.              If h[i] < h[i+1] then
  92.                 Begin
  93.                    k:=k+1;
  94.                 End;
  95.              i:=i+1 ;
  96.           End;
  97.    writeln('There are ',k,' towers which you can see from tower0');
  98.    readln ;
  99.    readln ;
  100. End;
  101. Procedure Main;
  102. Var
  103.    k:integer;
  104.    Begin
  105.    InPut;
  106.    OutPut(k);
  107.    End;
  108. Begin
  109.    Main;
  110. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement