#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<iterator>
using namespace std; #define ONLine ("on-line")
struct Record
{
Record(){};
Record(char *szName,char* szTime,char* szOnline)
{
bOnline = (strcmp(szOnline,ONLine)==);
strName = szName;
strTime = szTime;
}
string strName;
string strTime;
bool bOnline;
};
struct RecordTime
{
string strStartTime;
string strEndTime;
RecordTime(string starttime,string endtime)
{
strStartTime = starttime;
strEndTime = endtime;
}
RecordTime(){}
};
struct MyTime
{
MyTime(){};
MyTime(const char *cTime)
{
dd = *(cTime[]-'')+(cTime[]-'');
hh = *(cTime[]-'')+(cTime[]-'');
mm = *(cTime[]-'')+(cTime[]-'');
iTick = dd**+hh*+mm;
}
int dd;
int hh;
int mm;
int iTick;
};
int iPrice[];
map<string,int> mapRecord;
vector<Record> vcRecord[];
vector<RecordTime> vcDisplay[];
bool Comp(const Record& r1,const Record& r2)
{
return r1.strTime.compare(r2.strTime)<;
}
int getOneDayBill()
{
int iSum = ;
for(int i=;i<;++i)
iSum += (*iPrice[i]);
return iSum;
}
float DisplayOneCall(const RecordTime &rt)
{
string outStartTime = rt.strStartTime.substr(,);
string outEndTime = rt.strEndTime.substr(,);
printf("%s %s ",outStartTime.c_str(),outEndTime.c_str());
MyTime mtime1(outStartTime.c_str()),mtime2(outEndTime.c_str());
int iTotalTime = mtime2.iTick - mtime1.iTick;
float fTatalBill = 0.0f; //计算账单,用每一分钟遍历,可以AC
/*for(int dd=mtime1.dd,hh=mtime1.hh,mm=mtime1.mm;
!(dd==mtime2.dd&&hh==mtime2.hh&&mm==mtime2.mm);)
{
fTatalBill += iPrice[hh];
if(++mm == 60)
{
mm = 0;
++hh;
}
if(hh == 24)
{
hh = 0;
++dd;
}
}
*/
//把中间几个整天提出来,然后剩余的按分钟遍历,可以AC
/*int iDay = iTotalTime/60/24;
fTatalBill += iDay*getOneDayBill();
for(int hh=mtime1.hh,mm=mtime1.mm;
!(hh==mtime2.hh&&mm==mtime2.mm);)
{
fTatalBill += iPrice[hh];
if(++mm == 60) mm = 0,++hh;
if(hh == 24) hh = 0;
}
*/ int iDay = iTotalTime//;
fTatalBill += iDay*getOneDayBill();
if((mtime1.hh > mtime2.hh)
|| (mtime1.hh == mtime2.hh&&(mtime1.mm> mtime2.mm)))
mtime2.hh += ;
if(mtime1.hh == mtime2.hh && mtime2.mm>mtime1.mm)
fTatalBill += iPrice[mtime1.hh]*(mtime2.mm-mtime1.mm);
else
for(int hh = mtime1.hh;hh<=mtime2.hh;++hh)
{
if(hh == mtime1.hh)
fTatalBill += iPrice[hh%]*(-mtime1.mm);
else if(hh == mtime2.hh)
fTatalBill += iPrice[hh%]*(mtime2.mm);
else
fTatalBill += iPrice[hh%]*();
}
fTatalBill = 1.0*fTatalBill/;
printf("%d $%.2f\n",iTotalTime,fTatalBill);
return fTatalBill;
}
int main()
{
for(int i=;i<;++i)
scanf("%d",&iPrice[i]);
int n;
scanf("%d",&n);
int cnt=;
for(int i=;i<n;++i)
{
char szName[],szTime[],szOnline[];
scanf("%s%s%s",szName,szTime,szOnline);
Record record(szName,szTime,szOnline);
if(mapRecord.find(szName)==mapRecord.end())
{
mapRecord[szName] = cnt++;
}
vcRecord[mapRecord[szName]].push_back(record);
}
for(int i=;i<cnt;++i)
{
sort(vcRecord[i].begin(),vcRecord[i].end(),Comp);
int iFindOnLine = -;
for(int j=;j<vcRecord[i].size();++j)
{
if(vcRecord[i][j].bOnline==false && iFindOnLine != -)
{
RecordTime rt(vcRecord[i][iFindOnLine].strTime,
vcRecord[i][j].strTime);
vcDisplay[i].push_back(rt);
iFindOnLine = -;
}
else if(vcRecord[i][j].bOnline)
{
iFindOnLine = j;
}
}
} map<string,int>::iterator it = mapRecord.begin();
for(;it != mapRecord.end();it++)
{
int i = it->second;
if(vcDisplay[i].size()> )
{
string strYue = vcRecord[i][].strTime.substr(,);
printf("%s %s\n",it->first.c_str(),strYue.c_str());
float fSum = ;
for(int j=;j<vcDisplay[i].size();++j)
fSum +=DisplayOneCall(vcDisplay[i][j]);
printf("Total amount: $%.2f\n",fSum);
}
else
{ }
} return ;
}

PAT甲级1016Phone Bills的更多相关文章

  1. PAT甲级1016. Phone Bills

    PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...

  2. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  3. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

  4. PAT甲级1131. Subway Map

    PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...

  5. PAT甲级1127. ZigZagging on a Tree

    PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...

  6. PAT甲级1123. Is It a Complete AVL Tree

    PAT甲级1123. Is It a Complete AVL Tree 题意: 在AVL树中,任何节点的两个子树的高度最多有一个;如果在任何时候它们不同于一个,则重新平衡来恢复此属性.图1-4说明了 ...

  7. PAT甲级1119. Pre- and Post-order Traversals

    PAT甲级1119. Pre- and Post-order Traversals 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二进制树可以通过给定的一对后序和顺序遍历序列来确定,也可以通 ...

  8. PAT甲级1114. Family Property

    PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...

  9. PAT甲级1111. Online Map

    PAT甲级1111. Online Map 题意: 输入我们当前的位置和目的地,一个在线地图可以推荐几条路径.现在你的工作是向你的用户推荐两条路径:一条是最短的,另一条是最快的.确保任何请求存在路径. ...

随机推荐

  1. codeforces 371D

    #include<stdio.h> #define N 210000 struct node { int x,next; __int64 count,vec; }pre[N]; int n ...

  2. 特种部队(codevs 1427)

    题目描述 Description 某特种部队接到一个任务,需要潜入一个仓库.该部队士兵分为两路,第一路士兵已经在正面牵制住了敌人,第二路士兵正在悄悄地从后方秘密潜入敌人的仓库.当他们到达仓库时候,发现 ...

  3. WinForm 中限制只能输入数字

    在Winform(C#)中要实现限制Textbox只能输入数字,一般的做法就是在按键事件中处理,判断keychar的值.限制只能输入数字,小数点,Backspace,del这几个键.数字0~9所对应的 ...

  4. Spring MVC集成thymeleaf时提示:defined in ServletContext resource [/WEB-INF/SrpingMVCTest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException

    错误提示: defined in ServletContext resource [/WEB-INF/SrpingMVCTest-servlet.xml]: Instantiation of bean ...

  5. Spring Tool Suite(STS)启动时出现错误:Java was started but returned exit code=13问题解决

    Spring Tool Suite(STS)是开发Spring的套件,也就是一个Eclipse,在之上增加了对Spring框架的支持,使其能快速的开发Spring. 错误如下: 解决办法: 如果系统安 ...

  6. qt自己定义搜索框(超简单,带效果图)

    1. 什么也不要说.先上效果图: 2. 代码 头文件: #ifndef APPSEARCHLINE_H #define APPSEARCHLINE_H #include <QLineEdit&g ...

  7. SVM学习(续)核函数 & 松弛变量和惩罚因子

    SVM的文章可以看:http://www.cnblogs.com/charlesblc/p/6193867.html 有写的最好的文章来自:http://www.blogjava.net/zhenan ...

  8. Android:Unable to resolve target ‘android-8’问题解决

    在学习过程中,下载别人写过的代码,导入到eclipse,报错: Unable to resolve target 'android-8' 问题是项目版本号问题. 解决方法例如以下: 右击项目:Prop ...

  9. windows bat命令 开启关闭Oracle服务

    0.吐槽 单位发的ThinkPad T61.太弱小了. 问题是我去百度下T61,发现它好贵好贵.真心无力吐槽.还不如给我发台外星人,廉价点的. . Oracle一开就内存就不够了.所以绝对不能让它开机 ...

  10. ganglia收集hbase的metrics

    Ganglia 是 UC Berkeley 发起的一个开源监视项目,设计用于測量数以千计的节点.每台计算机都执行一个收集和发送度量数据(如处理器速度.内存使用量等)的名为 gmond 的守护进程.它将 ...