```c #include <stdio.h> #include <stdlib.h> typedef struct { int bookNumber; int startTimeHour; int startTimeMinute; int endTimeHour; int endTimeMinute; int isBorrowed; } BookRecord; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { BookRecord records[1000]; int recordCount = 0; int borrowCount = 0; int totalReadTime = 0; while (1) { int bookNumber; char key; int hour, minute; scanf("%d %c %d:%d", &bookNumber, &key, &hour, &minute); if (bookNumber == 0) { break; } if (key =='s') { records[recordCount].bookNumber = bookNumber; records[recordCount].startTimeHour = hour; records[recordCount].startTimeMinute = minute; records[recordCount].isBorrowed = 1; recordCount++; } else if (key == 'e') { int found = 0; for (int j = 0; j < recordCount; j++) { if (records[j].bookNumber == bookNumber && records[j].isBorrowed == 1) { records[j].endTimeHour = hour; records[j].endTimeMinute = minute; records[j].isBorrowed = 0; found = 1; int startTimeInMinutes = records[j].startTimeHour * 60 + records[j].startTimeMinute; int endTimeInMinutes = hour * 60 + minute; totalReadTime += endTimeInMinutes - startTimeInMinutes; borrowCount++; break; } } if (!found) { continue; } } } printf("%d %d\n", borrowCount, totalReadTime / borrowCount); } return 0; } ``` 额外需要注意的逻辑点: 1. 处理输入数据时,要确保格式的正确性,避免因输入错误导致程序异常。 2. 对于借阅和归还时间的计算,要考虑时间跨越 0 点的情况。 3. 程序中的数组大小要根据实际需求合理设置,避免内存溢出。 [2024-12-02 19:37:43 | AI写代码神器 | 581点数解答]