L1-043 阅览室


/*注意一下 这阅览室借书的测试是多人借的话算最后一个人借书的时间
让前面借书的无效,具体代码体现在59-65行
    if (maps.count(num) == 0) {
                maps.insert({ num,time });
            }
            else{
                maps[num]=time;
            }
*/
#include<iostream>
#include<map>
using namespace std;
int caculateTime(string time) {
    string s1, s2;
    bool flag = false;
    for (int i = 0; i < time.length(); i++) {
        if (!flag) {
            if (time[i] == ':') {
                flag = !flag;
            }
            else s1 += time[i];
        }
        else s2 += time[i];
    
    }
    int sum = 0;
    if (s1[0] == '0') { sum += (s1[1] - '0') * 60; }
    else sum += ((s1[1] - '0') + (s1[0] - '0') * 10) * 60;
    if (s2[0] == '0') { sum += (s2[1] - '0'); }
    else sum += ((s2[1] - '0') + (s2[0] - '0') * 10);
    return sum;
}
int getTime(string time1, string time2) {
   return caculateTime(time2)-caculateTime(time1);
}
int main() {
    int n;
    cin >> n;
    int flag = 0;
    map<int, string>maps;
    int num;//书号
    char c;//借/还
    string  time;//借还时间
    float calculateTimes = 0;//每天的总时间
    float times = 0;//每天的总次数
    while (flag < n) {
        cin >> num >> c >> time;
        if (num == 0) {
            flag++;
            if(times!=0)
            cout << times << " " << (int)(calculateTimes / times+0.5) << endl;
            else  cout << times << " " << 0 << endl;
            times = 0;
            calculateTimes = 0;
            maps.clear();
            continue;
        }
        if (c == 'S') {
            if (maps.count(num) == 0) {
                maps.insert({ num,time });
            }
            else{
                maps[num]=time;
            }
        }
        else {
            if (maps.count(num) == 1) {
                calculateTimes+= getTime(maps[num], time);
                times++;
                maps.erase(num);
            }
        }
    }

}

注意一下 这阅览室借书的测试是多人借的话算最后一个人借书的时间
让前面借书的无效,具体代码体现在59-65行

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值