pat 甲级 1016
2018-03-06 23:50
260 查看
pat 甲级 1016
错了n边,还是英语阅读能力不行啊,卡在没有成功匹配的用户不用输出上.
错了n边,还是英语阅读能力不行啊,卡在没有成功匹配的用户不用输出上.
#include<iostream> #include<algorithm> #include<cstring> using namespace std; int cost[24], day_cost; struct recoder { string name; int month; int _time; bool state; bool operator<(recoder r) { if(this->name == r.name) return this->_time < r._time; return this->name<r.name; } }re[1005]; int calcMoney(int time1 ,int time2) { int sum = 0; for(int i= time1;i<time2;i++) { sum+=cost[(i%(24*60))/60]; } printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",time1/(24*60),(time1%(24*60))/60, time1%60, time2/(24*60),(time2%(24*60))/60, time2%60,time2-time1, sum/100.0); return sum; } int main() { int n, i, month; string name, status; for(i=0;i<24;i++) { cin>>cost[i]; day_cost+=cost[i]*60; } cin>>n; for(i=0;i<n;i++) { int a, b, c; char t_name[20], t_state[20]; scanf("%s %d:%d:%d:%d %s",t_name, &month, &a, &b, &c, t_state); re[i].month = month; re[i].name = t_name; re[i]._time = a*24*60 + b*60 +c; if(!strcmp(t_state,"on-line")) re[i].state = true; else re[i].state = false; } sort(re,re+n); int sum = 0, start = 0, end = 0; name = re[0].name; for(i = 1;i<n;i++) { if(name == re[i].name) { if(re[i].state == false && re[i-1].state == true) { if(start == 0) { cout<<name; printf(" %02d\n",re[i].month); start = 1; end = 1; } sum+=calcMoney(re[i-1]._time, re[i]._time); } } else { if(end == 1) printf("Total amount: $%.2f\n",sum/100.0); name = re[i].name; start = 0; end = 0; sum = 0; } } if(end == 1) printf("Total amount: $%.2f\n",sum/100.0); return 0; }
相关文章推荐
- 【PAT甲级】1016. Phone Bills (25)
- PAT甲级 1016
- 1016. Phone Bills (25)-PAT甲级真题
- pat-甲级1016-Phone Bills
- PAT 甲级 1016. Phone Bills (25)
- PAT(甲级) 1016. Phone Bills (25)
- [PAT甲级]1016. Phone Bills (25)(统计用户每月电话账单)
- PAT甲级1016
- 1016. Phone Bills (25) PAT甲级
- PAT 甲级 1016. Phone Bills
- PAT甲级1016
- PAT(甲级)1016
- PAT 甲级 1016 Phone Bills
- PAT(甲级)1016. Phone Bills (25)
- PAT - 甲级 - 1016. Phone Bills (25)(排序)
- PAT 甲级 1016. Phone Bills (25)
- [PAT-甲级]1016.Phone Bills
- PAT甲级1016. Phone Bills (25)
- PAT_1016: Phone Bills
- PAT甲级1010:Radix