```python import datetime def calculate_borrow_info(records): # 存储每本书的借阅时间 book_times = {} # 有效借阅次数 valid_borrow_times = 0 # 总阅读时间(分钟) total_read_time = 0 for record in records: book_id, key, time_str = record time = datetime.datetime.strptime(time_str, "%H:%M") if key =='s': if book_id not in book_times: book_times[book_id] = time elif key == 'e': if book_id in book_times: start_time = book_times.pop(book_id) read_time = (time - start_time).total_seconds() / 60 total_read_time += read_time valid_borrow_times += 1 # 计算平均阅读时间 average_read_time = int(total_read_time / valid_borrow_times) if valid_borrow_times > 0 else 0 return valid_borrow_times, average_read_time n = int(input()) for _ in range(n): records = [] while True: line = input().split() if line[0] == '0': break records.append((int(line[0]), line[1], line[2])) borrow_times, average_time = calculate_borrow_info(records) print(f"{borrow_times} {average_time}") ``` 额外需要注意的逻辑点: 1. 对于时间的处理要准确,确保能正确计算阅读时长。 2. 处理无效纪录时要确保不影响有效借阅的统计。 3. 注意边界情况,比如第一天的开始时间和最后一天的结束时间。 [2024-11-30 10:47:03 | AI写代码神器 | 395点数解答]