L1-043 閱覽室 分數 20

Frodnx發表於2024-08-21

注意有大坑:題目沒有說,如果同一個書號出現兩個'S',按照後者記時(一本書在未歸還時被多次借出,記錄取後者)。

// long
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
int main()
{
    int n;
    cin >> n;
    map<int, pair<bool,int> > borw;
    int sumtime = 0, amount = 0;
    int cnt = 0;
    while(cnt < n)
    {
        int bnum;
        char c, emp;
        int n1, n2;
        cin >> bnum >> c >> n1 >> emp >> n2;
        if(bnum > 1000) continue;
        if(bnum == 0)
        {
        	++ cnt;
        	cout << amount << " " << (amount == 0 ? 0 : round((double)(sumtime) / (double)(amount))) << endl;
        	amount = 0;
        	sumtime = 0;
        	borw.clear();
        	continue;
        }
        if(c == 'S')
        {
            // 此處不能加限制條件,否則測試點1會被卡
            //if(borw[bnum].x == false)
            //{
        	borw[bnum].x = true;
        	borw[bnum].y = n1 * 60 + n2;
            //}
        }
        else if(c == 'E')
        {
        	if(borw[bnum].x == true)
        	{
        		sumtime += n1 * 60 + n2 - borw[bnum].y;
        		borw[bnum].x = false;
        		borw[bnum].y = 0;
        		++ amount;
        	}
        }
     }
    return 0;
}

相關文章