PAT(甲) - 1016 Phone Bills

注意审题:“It is guaranteed that at least one call is well paired in the input.” 只是说了输入中有配对的记录,但并没有说每个人都有配对的记录,因此存在个人话费为0的情况,此时什么都不需要输出(包括名字)

#include <bits/stdc++.h>
using namespace std;

typedef struct
{
    string name;
    int stamp;
    int status;
} record;

typedef struct
{
    int MM;
    int dd;
    int HH;
    int mm;
} times;

int times2stamp(times t)
{
    return t.mm + t.HH * 60 + t.dd * 60 * 24 + t.MM * 60 * 24 * 31;
}

times stamp2times(int stamp)
{
    times t;
    t.mm = stamp % 60;
    t.HH = stamp / 60 % 24;
    t.dd = stamp / 60 / 24 % 31;
    t.MM = stamp / 60 / 24 / 31;
    return t;
}

bool time_order(record a, record b)
{
    return a.stamp < b.stamp;
}

int main()
{
    int charge[24];
    for (int i = 0; i < 24; i++)
    {
        cin >> charge[i];
    }
    int count;
    cin >> count;
    record records[count];
    for (int i = 0; i < count; i++)
    {
        times t;
        char c;
        cin >> records[i].name >> t.MM >> c >> t.dd >> c >> t.HH >> c >> t.mm;
        records[i].stamp = times2stamp(t);
        string temp;
        cin >> temp;
        if (temp == "on-line")
            records[i].status = 0;
        else
            records[i].status = 1;
    }
    sort(records, records + count, time_order);
    set<string> names;
    for (int i = 0; i < count; i++)
    {
        names.insert(records[i].name);
    }
    set<string>::iterator it;
    for (it = names.begin(); it != names.end(); it++)
    {
        bool first = 1;
        int total_money = 0;
        int on = -1;
        for (int i = 0; i < count; i++)
        {
            if (records[i].name == *it && records[i].status == 0)
                on = i;
            if (records[i].name == *it && records[i].status == 1 && on != -1)
            {
                times t1, t2;
                t1 = stamp2times(records[on].stamp);
                t2 = stamp2times(records[i].stamp);
                int money = 0;
                for (int j = records[on].stamp; j < records[i].stamp;)
                {
                    times t = stamp2times(j);
                    if (t.mm == 0 && j + 59 < records[i].stamp)
                    {
                        money += charge[t.HH] * 60;
                        j += 60;
                    }
                    else
                    {
                        money += charge[t.HH];
                        j++;
                    }
                }
                if (first)
                {
                    cout << *it << " ";
                    printf("%02d\n", stamp2times(records[0].stamp).MM);
                    first = 0;
                }
                printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", t1.dd, t1.HH, t1.mm, t2.dd, t2.HH, t2.mm, records[i].stamp - records[on].stamp, money * 1.0 / 100);
                total_money += money;
                on = -1;
            }
        }
        if (total_money != 0)
            printf("Total amount: $%.2f\n", total_money * 1.0 / 100);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值