1016 Phone Bills

越做越恶心。。。

For each test case, you must print a phone bill for each customer.

print for each customer
花费为0的不是顾客。。。

#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

struct node {
    int dd, hh, mm;
    string st;
    node() {}
    node(int d, int h, int m, string s):dd(d), hh(h), mm(m), st(s) {}
    friend bool operator<(const node &a, const node &b) {
        if (a.dd == b.dd) {
            if (a.hh == b.hh) {
                return a.mm < b.mm;
            }else
                return a.hh < b.hh;
        }else
            return a.dd < b.dd;
    }
};

map<pair<string, int>, set<node> > mp;
int toll[25];

int cal(const node &a, const node &b) {
    printf("%02d:%02d:%02d ", a.dd, a.hh, a.mm);
    printf("%02d:%02d:%02d ", b.dd, b.hh, b.mm);
    int tm = b.mm - a.mm, fee = b.mm*toll[b.hh] - a.mm*toll[a.hh];
    int da = a.dd, ha = a.hh;
    while (da < b.dd) {
        do {
            tm += 60;
            fee += 60 * toll[ha];
            ha++;
            ha %= 24;
        }while (ha != 0);
        da++;
    }
    while (ha < b.hh) {
        tm += 60;
        fee += 60 * toll[ha];
        ha++;
    }
    printf("%d $%.2f\n", tm, (double)fee/100);
    return fee;
}

void sol(string name, int month, set<node> &s) {
    int sum = 0;
    bool on = false;
    node t;
    for (set<node>::iterator it = s.begin(); it != s.end(); it++) {
        if (it->st == "on-line") {
            t = *it;
            if (!on) 
                on = true;
        }else {
            if (on) {
                if (!sum) {
                    cout << name;
                    printf(" %02d\n", month);
                }
                sum += cal(t, *it);
                on = false;
            }
        }
    }
    if (sum)
        printf("Total amount: $%.2f\n", (double)sum/100);
}

int main() {
//  freopen("in", "r", stdin);
    for (int i = 0; i < 24; i++)
        scanf("%d", toll+i);
    int n;
    scanf("%d", &n);
    while (n--) {
        string name, st;
        int mon, day, hou, min;
        cin >> name;
        scanf("%d:%d:%d:%d", &mon, &day, &hou, &min);
        cin >> st;
        mp[make_pair(name, mon)].insert(node(day, hou, min, st));
    }
    for (map<pair<string, int>, set<node> >::iterator it = mp.begin(); it != mp.end(); it++) 
        sol(it->first.first, it->first.second, it->second);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值