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+1);
- SetLength(h,ArrayLength+1);
- N:=ArrayLength;
- IsCorrect:=True;
- Except
- Writeln('Error.Try again');
- End;
- Until (IsCorrect) and (ArrayLength > 0);
- 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');
- For i := 1 to N do
- Repeat
- IsCorrect:=False;
- Try
- Write('x[',i,'],h[',i,']=');
- Read (x[i],h[i]);
- IsCorrect:=True;
- 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 := 2 to N do
- If h[i]> Max then
- Begin
- Max := h[i];
- Xhmax := x[i];
- End;
- End ;
- Function Visability(k: integer): integer ;
- Begin
- k:=1; {You can see Tower 1 in any case}
- i:=1;
- If h0 < Max then
- While x[i] <= Xhmax do
- Begin
- If h[i] < h[i+1] then
- Begin // consideration of overlaying situation
- k:=k+1;
- End;
- i:=i+1;
- End;
- If h0 > Max Then
- While x[i] <= x[N] do
- Begin
- Repeat
- k:=k+1;
- i:=i+1 ;
- Until h[i]>h[i+1];
- If h[i] < h[i+1] then
- Begin
- k:=k+1;
- End;
- i:=i+1;
- End;
- if h0 = Max Then
- While x[i] <= Xhmax do
- Begin
- If Max <> h [i] then
- k:=k+1;
- If h[i] < h[i+1] then
- Begin // consideration of overlaying situation
- k:=k+1;
- End;
- i:=i+1 ;
- End;
- End;
- procedure OutPut;
- Begin
- writeln('There are ',k,'towers which you can see from tower0');
- readln ;
- End;
- Procedure Main;
- Begin
- InPut;
- Maximum(Max,Xhmax);
- k:=Visability(k);
- OutPut;
- End;
- Begin
- Main;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement