Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Laba1;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- Var
- N,k,h0,i : integer ;
- x: array of integer;
- h: array of integer;
- Max,Xhmax:integer;
- procedure Input ;
- Var
- ArrayLength: integer;
- IsCorrect: boolean;
- Begin
- Repeat
- Writeln('Please,enter N and H,where H is the hight of tower 0 and N is a quantity of towers. ');
- Writeln('All the items must be integer');
- IsCorrect:=False;
- Try
- Write('Tower 0 [N,h0]:');
- Read(ArrayLength,h0);
- SetLength(x,ArrayLength);
- IsCorrect:=True;
- Except
- Writeln('Error.Try again');
- End;
- Until (IsCorrect) and (ArrayLength>0);
- Repeat
- Writeln('Please,enter x and h,where h is the hight of a tower and x is its situation');
- Writeln('They must be positive and integer');
- IsCorrect:=False;
- Try
- For i := 1 to ArrayLength do
- Begin
- Write('x[',i,'],h[',i,']=');
- Read (x[i],h[i]);
- IsCorrect:=True;
- End;
- Except
- Writeln ('Error. Try again');
- End;
- Until (IsCorrect) and (h[i] > 0) ;
- End;
- Function Maximum(Var Max,Xhmax: integer): integer;
- Begin
- Max := h[1];
- Xhmax := x[1];
- For i := 1 to N do
- If h[i]> Max then
- Begin
- Max := h[i];
- Xhmax := x[i];
- End;
- End ;
- Function Visability(k: integer): integer ;
- Begin
- k:=0;
- i:=1;
- If h0 < Max then
- While x[i] <= Xhmax do
- Begin
- If h[i] < h[i+1] then // consideration of overlaying situation
- k:=k+1;
- i:=i+1;
- End;
- If h0 > Max Then
- While x[i] <= x[N] do
- Begin
- If h[i] < h[i+1] then
- k:=k+1;
- i:=i+1;
- End;
- if h0=Max Then
- While x[i] <= x[N] do
- Begin
- If Max = h[i] then
- k:=k;
- If Max <> h [i] then
- k:=k+1;
- i:=i+1
- End;
- writeln('There are ',k,'towers which you can see from tower0');
- readln;
- End;
- Procedure Main;
- Begin
- InPut;
- Maximum(Max,Xhmax);
- Visability(k);
- End;
- Begin
- Main;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement