pat 1016
来源:互联网 发布:淘宝导航全屏css代码 编辑:程序博客网 时间:2024/05/16 11:49
第一次用map STL,其中map<string,int>
,最好不要用char*做map的key,详见stackoverflows上的讨论
http://stackoverflow.com/questions/4157687/using-char-as-a-key-in-stdmap/4157811#4157811
要注意如果一个账户没有满足条件的账单,则它什么都不输出(名字也不输出)
#include<stdio.h>#include<iostream>#include<map>#include<vector>#include<algorithm>#include<string>#define SIZE 1000using namespace std;struct person{ string name; int month, day, hour, min; bool online;};int rate[24];bool cmp(const struct person &a, const struct person &b){ if (a.month == b.month) if (a.day == b.day) if (a.hour == b.hour) return a.min < b.min; else return a.hour < b.hour; else return a.day < b.day; else return a.month < b.month;}vector<struct person> custom;map<string, vector<struct person>> cus;map<string, vector<struct person>>::iterator it;void PrintNum(int n){ if (n < 10) printf("0%d", n); else printf("%d", n);}void PrintTime(const struct person &a){ PrintNum(a.day); putchar(':'); PrintNum(a.hour); putchar(':'); PrintNum(a.min);}double Cost(struct person &a,struct person &b){ double fee = 0; int minute = 0; while (a.day != b.day ||a.hour != b.hour||a.min != b.min){ fee += rate[a.hour]; minute++; a.min++; if (a.min >= 60) { a.min = 0; a.hour++; } if (a.hour >= 24){ a.hour = 0; a.day++; } } printf("%d ", minute); return fee/100;}int main(){ freopen("1.in", "r", stdin); int NumOfBill, NumOfPerson = 0; int i; for (i = 0; i < 24; i++) scanf("%d", &rate[i]); scanf("%d", &NumOfBill); string name,state; int day, month, hour, min; struct person node; int index; for (i = 0; i < NumOfBill; i++){ cin >> name; scanf("%d:%d:%d:%d",&month, &day, &hour, &min); cin >> state; node.name = name; node.month = month; node.day = day; node.hour = hour; node.min = min; if (state == "on-line") node.online = true; else node.online = false; cus[name].push_back(node); } //sort(cus.begin(), cus.end()); //printf("%d\n", cus.size()); vector<struct person>::iterator k; for (it = cus.begin(); it != cus.end(); it++){ custom = (*it).second; sort(custom.begin(), custom.end(), cmp); k = custom.begin(); while (k != custom.end()){ if ((*k).online) break; k++; } if (k == custom.end()||k+1 == custom.end()) continue; double totalfee = 0,fee = 0; struct person begin, end; bool flag = false; bool nameflag = false; for (; k != custom.end(); k++){ if ((*k).online){ begin = *k; flag = true; } else if (flag &&!(*k).online){ if (nameflag == false){ cout << (*k).name; putchar(' '); PrintNum((*k).month); putchar('\n'); nameflag = true; } end = *k; PrintTime(begin); putchar(' '); PrintTime(end); putchar(' '); fee = Cost(begin, end); totalfee += fee; printf("$%.2lf\n", fee); flag = false; } else continue; } if (nameflag) printf("Total amount: $%.2lf\n", totalfee); } return 0;}
0 0
- PAT 1016
- pat 1016
- PAT-1016
- pat basic level 1016
- PAT 1016 Phone Bills
- pat: 1016 A+B
- PAT (Basic) 1016~1020
- PAT Advanced Level 1016
- PAT 1016 Phone bills
- PAT(甲级)1016
- PAT乙级1016
- pat-bl-1016
- PAT甲级1016
- PAT 1016 Phone Bills
- pat乙级1016
- PAT甲级 1016
- PAT(乙级)1016
- PAT 乙级 1016
- H264—MP4格式及在MP4文件中提取H264的SPS、PPS及码流
- c++ 文本或二进制输出 fstream
- poj 2236 Wireless Network 并查集
- poj 2392 Space Elevator
- c++ 字符串与整型转换 sstream
- pat 1016
- 机器学习基石笔记7——为什么机器可以学习(3)
- c++11多线程应用之简易智能计数器
- 关于大型网站技术演进的思考(四)--存储的瓶颈(4)
- DirectShow学习笔记总结
- 从n个数里面选k个数,状态压缩的方法求解
- SlopeOne推荐算法实现(C++)
- poj1655Balancing Act(树的重心)
- Unique Paths II (DP)