#include #include #include #include

using namespace std;

struct Record { int bookId; char key; int hour; int minute; };

int main() { int N; cin >> N;

for (int i = 0; i < N; i++) {
    int borrowCount = 0;
    int borrowTime = 0;
    int lastHour = 0;
    int lastMinute = 0;
    map<int, Record> borrowRecords;
    
    while (true) {
        int bookId;
        char key;
        int hour;
        int minute;
        cin >> bookId >> key >> hour >> minute;
        
        if (bookId == 0) {
            if (borrowCount > 0) {
                cout << borrowCount << " " << borrowTime / borrowCount << endl;
            } else {
                cout << "0 0" << endl;
            }
            break;
        }
        
        if (key == 'S') {
            Record record;
            record.bookId = bookId;
            record.key = key;
            record.hour = hour;
            record.minute = minute;
            borrowRecords[bookId] = record;
        } else if (key == 'E') {
            if (borrowRecords.find(bookId) != borrowRecords.end()) {
                Record record = borrowRecords[bookId];
                borrowRecords.erase(bookId);
                
                int borrowDuration = (hour - record.hour) * 60 + (minute - record.minute);
                if (borrowDuration >= 0) {
                    borrowCount++;
                    borrowTime += borrowDuration;
                }
            }
        }
    }
}

return 0;

}

C++ 天梯图书阅览室借阅统计程序 - 优化代码,自动忽略无效记录

原文地址: https://www.cveoy.top/t/topic/pzz7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录