this time with no legal info
This commit is contained in:
38
5/ex1.py
Normal file
38
5/ex1.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import bisect
|
||||
|
||||
count = 0
|
||||
|
||||
intervals = []
|
||||
|
||||
with open("input.txt" , "r") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
break
|
||||
start, end = map(int, line.split("-"))
|
||||
intervals.append((start, end))
|
||||
|
||||
intervals.sort(key = lambda x: x[0])
|
||||
merged = [intervals[0]]
|
||||
|
||||
for current_start, current_end in intervals[1:]:
|
||||
last_start, last_end = merged[-1]
|
||||
if current_start <= last_end:
|
||||
merged[-1] = (last_start, max(last_end, current_end))
|
||||
else:
|
||||
merged.append((current_start, current_end))
|
||||
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
starts = [i[0] for i in merged]
|
||||
number = int(line)
|
||||
|
||||
index = bisect.bisect_right(starts, number)
|
||||
if index == 0:
|
||||
continue
|
||||
start, end = merged[index - 1]
|
||||
if start <= number <= end:
|
||||
count += 1
|
||||
|
||||
print(count)
|
||||
|
||||
Reference in New Issue
Block a user