1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include<iostream> #include<map> #include<vector> #include<algorithm> using namespace std; const int maxn = 1010; int N, rate[25]; struct node { string name; int status, mon, day, hour, minute, time; }; bool cmp(node* a, node* b) { if (a->name != b->name) return a->name < b->name; return a->time < b->time; } vector<node*>bill; map<string, int>id; double money(node* a) { double total = rate[a->hour] * a->minute + rate[24] * 60 * a->day; for (int i = 0; i < a->hour; i++) { total += rate[i] * 60; } return total/100.0; } int main() { for (int i = 0; i < 24; i++) { cin >> rate[i]; rate[24] += rate[i]; } cin >> N; string name, act; int M, d, H, m; int peoplenum = 0; for (int i = 0; i < N; i++) { cin >> name; scanf("%d:%d:%d:%d", &M, &d, &H, &m); cin >> act; if (id.count(name) == 0) id[name] = peoplenum++; node* p = new node(); p->name = name; p->mon = M; p->day = d; p->hour = H; p->minute = m; p->time = d * 24 * 60 + H * 60 + m; if (act == "on-line") p->status = 1; else p->status = 0; bill.push_back(p); } map<string, vector<node*>>cost; sort(bill.begin(), bill.end(), cmp); for (int i = 0; i < bill.size()-1; i++) { if (bill[i]->name == bill[i + 1]->name && bill[i]->status == 1 && bill[i + 1]->status == 0) { cost[bill[i]->name].push_back(bill[i]); cost[bill[i]->name].push_back(bill[i + 1]); } } for (auto it : cost) { vector<node*>temp = it.second; double total = 0; printf("%s %02d\n", it.first.c_str(), it.second[0]->mon); for (int i = 0; i < temp.size()-1;i++) { printf("%02d:%02d:%02d %02d:%02d:%02d ", temp[i]->day, temp[i]->hour, temp[i]->minute, temp[i+1]->day, temp[i+1]->hour, temp[i+1]->minute); cout << temp[i + 1]->time - temp[i]->time<<" "; double m = money(temp[i + 1]) - money(temp[i]); total += m; printf("\$%.02f\n", m); i++; } printf("Total amount: "); printf("\$%.02f\n", total); } }
|