把output改成不要印出所有值班的人
改成印誰在哪個時間點上班
在哪個時間點下班
就不用每次hard copy
加上sorted() 會變成hard copy


```=python
def merge_intervals(data):
events = []
for name, start, end in data:
events.append((start, name, 'start'))
events.append((end, name, 'end'))
# Sort events primarily by time, handling edge case where end and start time are the same (end should come first).
events.sort(key=lambda x: (x[0], x[2] == 'start'))
active_names = set()
previous_time = None
merged_intervals = []
for time, name, etype in events:
if active_names and previous_time is not None and previous_time != time:
merged_intervals.append((previous_time, time, sorted(active_names)))
if etype == 'start':
active_names.add(name)
else:
active_names.remove(name)
previous_time = time
return merged_intervals
def get_rotation_table(data):
intervals = merge_intervals(data)
rotation_table = []
for start, end, names in intervals:
rotation_table.append((start, end, names))
return rotation_table
# Example input
data = [
('Abby', 10, 100),
('Ben', 50, 70),
('Carla', 60, 120),
('David', 150, 300)
]
# Get the rotation table
rotation_table = get_rotation_table(data)
# Print the output
print("Start | End | Names")
print("----- | ---- | -----")
for start, end, names in rotation_table:
print(f"{start:<5} | {end:<4} | {', '.join(names)}")
```

