PATA-1016Phone Bills (25)
来源:互联网 发布:保密三合一软件 编辑:程序博客网 时间:2024/05/25 12:20
代码来自http://blog.csdn.net/cstopcoder/article/details/25559285?utm_source=tuicool&utm_medium=referral
题意:
对于给定的电话单子进行处理,注意:on必须后面有一个off匹配。而且如果这个单子不合理就不输出。PAT题里根本没叙述还有这测试点,坑死人。
思路:
自己想用map试一下,但是不太会it->second的排序,恰好网上有个写的很好的。
#include<cstdio>#include<iostream>#include<string>#include<map>#include<vector>#include<algorithm>using namespace std;typedef struct Calls{int month;int day;int hour;int minute;string word;}Calls;bool cmp(const Calls &l,const Calls &r){if(l.day<r.day)return true;else if(l.day==r.day&&l.hour<r.hour)return true;else if(l.day==r.day&&l.hour==r.hour&&l.minute<r.minute)return true;elsereturn false;}map<string,vector<Calls> > m;//存储名字对应的通话记录int Rate[24];float ComputeFee(Calls l,Calls r,int *totaltime)//计算通话费用{float fee=0;*totaltime=0;while(l.day<r.day||l.hour<r.hour||l.minute<r.minute){fee+=Rate[l.hour];(*totaltime)++;l.minute++;if(l.minute==60){l.minute=0;l.hour++;if(l.hour==24){l.hour=0;l.day++;}}}return fee;}int main(int argc,char *argv[]){int i,j;int n;for(i=0;i<24;i++)cin>>Rate[i];cin>>n;for(i=0;i<n;i++){string name;Calls temp;cin>>name;scanf("%d:%d:%d:%d",&temp.month,&temp.day,&temp.hour,&temp.minute);cin>>temp.word;m[name].push_back(temp);}map<string,vector<Calls> >::iterator it;vector<Calls>::iterator p;for(it=m.begin();it!=m.end();it++){sort((it->second).begin(),(it->second).end(),cmp);} for(it=m.begin();it!=m.end();it++){ int FindPair=false;int totaltime=0;float total=0;for(p=(it->second).begin();p!=(it->second).end();p++){ Calls temp=*p;if(temp.word[1]=='n'){if((p+1)!=(it->second).end()){Calls next=*(p+1);if(next.word[1]=='f'){if(!FindPair){cout<<it->first;printf(" %02d\n",p->month);FindPair=true;} printf("%02d:%02d:%02d %02d:%02d:%02d",temp.day, temp.hour,temp.minute,next.day,next.hour,next.minute); float fee=ComputeFee(temp,next,&totaltime);printf(" %d $%.2f\n",totaltime,fee/100);total+=fee;}}}}if(FindPair) printf("Total amount: $%.2f\n",total/100);} return 0;}
0 0
- PATA-1016Phone Bills (25)
- 1016 Phone Bills (25)
- 1016 重要Phone Bills (25)
- PAT 1016 Phone Bills (25)
- PAT 1016 Phone Bills
- PAT 1016 Phone bills
- 1016 Phone Bills
- 1016 Phone Bills
- PAT 1016 Phone Bills
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 清除页面广告,一款简易的chrome扩展
- Scade——学习笔记(2)
- 深入浅出JMS(ActiveMQ)
- SQL数据库进程阻塞导致客户端无法插入数据
- adb环境配置
- PATA-1016Phone Bills (25)
- PHP基础补全系列:Trait
- [Oracle]创建序列sequence
- Android开发中的一些框架(一)
- 纯css修改滚动条样式颜色
- InstallShield 博客
- Android Context 上下文
- JS动态修改页面EasyUI datebox不生效、EasyUI动态添加Class、EasyUI动态渲染解析解决方案
- oracle JOB 查询 添加 修改 删除 运行