PAT (Advanced) 1016. Phone Bills (25)

#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);
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值