先说结论:yxcnb!
#include <bits/stdc++.h>
using namespace std;
int rate[25], n;
struct node {
string name;
int status, month, time, day, hour, minute;
};
//CYLL 01:01:06:01 on-line
//name month:day:hour:minute status + time(总时间)
bool cmp(node a, node b) {
return a.name != b.name ? a.name < b.name : a.time < b.time;
// 花里胡哨的三元表达式, 名字不同按照字典序排,相同按照总时间排序
// y总直接把名字和信息分开,依照map内部红黑树的特性,姓名自然按照字典序排列
// unordered_map 从字面意思看就不可以,内部是无序的。为什么不叫hash ???,谁让STL实现的比较晚
// 被第三方包把hash这个名字占用了
}
// 对比y总的递推前缀和
// for (int i = 1; i < M; i ++ ) sum[i] = sum[i - 1] + cost[(i - 1) % 1440 / 60] / 100.0;
// yxcnb!
double billFromZero(node call) {
double total = rate[call.hour] * call.minute + rate[24] * 60 * call.day;
for (int i = 0; i < call.hour; i++)
total += rate[i] * 60;
return total / 100.0;
}
int main() {
// 读入24个时段的话费,把一天的话费和存在rate[24]
for (int i = 0; i < 24; i++) {
scanf("%d", &rate[i]);
rate[24] += rate[i];
}
scanf("%d", &n);
vector<node> data(n); // 开一个vector来保存记录
string state;
for (int i = 0; i < n; i++) {
// CYLL 01:01:06:01 on-line 读入6个量到vector,这里y总直接就存入map了
// 还有sprintf太骚了,后期写省事++
cin >> data[i].name;
scanf("%d:%d:%d:%d", &data[i].month, &data[i].day, &data[i].hour, &data[i].minute);
cin >> state; // 读入状态
// 没太看懂这里用三元的必要,在底下直接写=="on-line"不香吗
data[i].status = (state == "on-line") ? 1 : 0;
// 计算总时间 ? 为啥不减1, 其实-1意义更加准确,不减因为算的是时间差也无所谓
data[i].time = data[i].day * 24 * 60 + data[i].hour * 60 + data[i].minute;
}
sort(data.begin(), data.end(), cmp); //将所有数据排排坐
map<string, vector<node> > custom;
for (int i = 1; i < n; i++) {
if (data[i].name == data[i - 1].name && data[i - 1].status == 1 && data[i].status == 0) {
// 满足条件了,放入map
custom[data[i - 1].name].push_back(data[i - 1]);
custom[data[i].name].push_back(data[i]);
}
}
//然后在开始处理map里面的,此时map内全部都是满足条件的,输出就OK
/* CYJJ 01
01:05:59 01:07:00 61 $12.10
Total amount: $12.10
*/
for (auto &it : custom) {
vector<node> record = it.second;
cout << it.first;
printf(" %02d\n", record[0].month);
double total = 0.0;
for (int i = 1; i < record.size(); i += 2) {
double t = billFromZero(record[i]) - billFromZero(record[i - 1]);
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",
record[i - 1].day, record[i - 1].hour, record[i - 1].minute,
record[i].day, record[i].hour, record[i].minute,
record[i].time - record[i - 1].time, t);
total += t;
}
printf("Total amount: $%.2f\n", total);
}
return 0;
}