#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
struct Call
{
int month, dd, hh, mm;
string tag;
};
bool cmp(const Call &a, const Call &b)
{
if (a.dd != b.dd)
return a.dd < b.dd;
else if (a.hh != b.hh)
return a.hh < b.hh;
else
return a.mm < b.mm;
}
map<string, vector<Call>> m;
int rate[24];
double compute_fee(Call a, Call b, int &total_time)
{
double fee = 0;
total_time = 0;
while (a.dd < b.dd || a.hh < b.hh || a.mm < b.mm)
{
fee += rate[a.hh];
total_time++;
a.mm++;
if (a.mm == 60)
{
a.mm = 0;
a.hh++;
if (a.hh == 24)
{
a.hh = 0;
a.dd++;
}
}
}
return fee;
}
int main()
{
for (int i = 0; i < 24; i++)
cin >> rate[i];
int n;
cin >> n;
string name;
Call temp;
for (int i = 0; i < n; i++)
{
cin >> name;
scanf("%d:%d:%d:%d", &temp.month, &temp.dd, &temp.hh, &temp.mm);
cin >> temp.tag;
m[name].push_back(temp);
}
for (auto it = m.begin(); it != m.end(); ++it)
{
sort((it->second).begin(), (it->second).end(), cmp);
}
for (auto it = m.begin(); it != m.end(); ++it)
{
int pair = false;
int total_time = 0;
double total = 0;
for (auto p = (it->second).begin(); p != (it->second).end(); ++p)
{
temp = *p;
if (temp.tag[1] == 'n' && (p + 1) != (it->second).end())
{
Call next = *(p + 1);
if (next.tag[1] == 'f')
{
if (!pair)
{
printf("%s %02d\n", (it->first).c_str(), temp.month);
pair = true;
}
printf("%02d:%02d:%02d %02d:%02d:%02d", temp.dd, temp.hh, temp.mm, next.dd, next.hh, next.mm);
double fee = compute_fee(temp, next, total_time);
printf(" %d $%.2lf\n", total_time, fee / 100);
total += fee;
}
}
}
if (pair)
printf("Total amount: $%.2lf\n", total / 100);
}
}
PAT (Advanced) 1016. Phone Bills (25)
最新推荐文章于 2020-04-19 16:19:46 发布