越做越恶心。。。
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;
}