-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsatelite.py
More file actions
43 lines (36 loc) · 1016 Bytes
/
satelite.py
File metadata and controls
43 lines (36 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
def print_peak(pos, height):
print(f"distance {pos} height {height:.1f}")
def read_float():
line = sys.stdin.readline()
if not line:
return None
return float(line.strip())
prev = read_float()
curr = read_float()
pos = 1
while True:
nxt = read_float()
if nxt is None or nxt < 0:
break
if curr == nxt:
plateau_start = pos
plateau_height = curr
plateau_end = pos + 1
while True:
val = read_float()
if val is None or val < 0 or val != plateau_height:
break
plateau_end += 1
if prev < plateau_height and (val is None or val < plateau_height):
print_peak(plateau_end, plateau_height)
prev = curr
curr = val if val is not None and val >= 0 else None
pos = plateau_end
if curr is None:
break
continue
if curr > prev and curr > nxt:
print_peak(pos, curr)
prev, curr = curr, nxt
pos += 1