1016. Phone Bills (25)
分析:
模拟题,提交无数次WA,注意几点:
1.如果某人没有有效通话记录,则不输出该人的信息,在此WA15次,题目看了N遍也没出现啊。
2.通话时间钱的计算:假设我们计算time1到time2的账单;
(1)我们可以采用从起点(即00:00:00)开始计算,结果就是get_money(time2) - get_money(time1), 这样计算方便。
(2)我们也可以采用从time1开始递增直到time2, 这样比较烦。
3.有效的通话记录是指:如果某人的通话记录为1.on;2.on;3.off;
,则其中1.on
将被抛弃,匹配到2.on;3.off;
。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cctype>
#include <stack>
#include <map> using namespace std; int rate_structure[]; struct Person
{
string name;
int month;
int dd, hh, mm;
int total;
bool is_on_line;
}person[]; int cmp(const Person &a, const Person &b)
{
if (a.name != b.name)
return a.name < b.name;
else return a.total < b.total;
} double get_money(int idx) // 得到钱
{
double money = ; money += person[idx].dd * * rate_structure[];
for (int i = ; i < person[idx].hh; i++)
money += * rate_structure[i];
money += person[idx].mm * rate_structure[person[idx].hh]; return money / ;
} bool should_output(int idx, int n) //判断某人的记录是否有有效记录
{
int pre = -;
for (int i = idx; i < n; i++)
{
if (person[i].name == person[idx].name)
{
if (person[i].is_on_line == )
pre = i;
else if (person[i].is_on_line == )
{
if (pre != -) return ;
}
}
else return ;
}
return ;
} void work(int n)
{
string tmp = person[].name;
double sum = ;
int pre = -; //记录off_line前一个的on_line
bool flag = ; if (should_output(, n))
{
cout << person[].name;
printf(" %02d\n", person[].month);
flag = ;
}
for (int i = ; i < n; i++)
{
if (person[i].name != tmp)
{
if (flag == )
{
printf("Total amount: $%.2lf\n", sum);
flag = ;
} if (should_output(i, n))
{
cout << person[i].name;
printf(" %02d\n", person[i].month);
flag = ;
}
pre = -;
sum = ;
tmp = person[i].name;
} if (person[i].is_on_line == )
pre = i;
else if (person[i].is_on_line == )
{
if (pre != -)
{
printf("%02d:%02d:%02d ", person[pre].dd, person[pre].hh, person[pre].mm);
printf("%02d:%02d:%02d ", person[i].dd, person[i].hh, person[i].mm);
printf("%d ", person[i].total - person[pre].total); double money = get_money(i) - get_money(pre);
printf("$%.2lf\n", money);
sum += money;
pre = -;
}
}
}
if (flag == )
printf("Total amount: $%.2lf\n", sum);
} int main()
{
int n;
string status;
while (scanf("%d", &rate_structure[]) != EOF)
{
rate_structure[] = rate_structure[]; //用rate_structure[24]存储0-23之和
for (int i = ; i < ; i++)
{
scanf("%d", &rate_structure[i]);
rate_structure[] += rate_structure[i];
}
scanf("%d", &n); for (int i = ; i < n; i++)
{
cin >> person[i].name;
scanf("%d:%d:%d:%d", &person[i].month, &person[i].dd,
&person[i].hh, &person[i].mm);
cin >> status; person[i].total = person[i].dd * + person[i].hh * + person[i].mm;
person[i].is_on_line = (status == "on-line"? : );
} sort(person, person + n, cmp); work(n); //print(); }
return ;
}
1016. Phone Bills (25)的更多相关文章
- 1016. Phone Bills (25)——PAT (Advanced Level) Practise
题目信息: 1016. Phone Bills (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A l ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- 1016. Phone Bills (25) -vector排序(sort函数)
题目如下: A long-distance telephone company charges its customers by the following rules: Making a long- ...
- 1016 Phone Bills (25)(25 point(s))
problem A long-distance telephone company charges its customers by the following rules: Making a lon ...
- 1016 Phone Bills (25 分)
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- PAT A 1016. Phone Bills (25)【模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 ...
- 1016 Phone Bills (25分)
复建的第一题 理解题意 读懂题目就是一个活,所以我们用观察输出法,可以看出来月份,以及时间和费用之间的关系. 定义过程 然后时间要用什么来记录呢?day hour minute 好麻烦呀..用字符串吧 ...
- PAT (Advanced Level) 1016. Phone Bills (25)
简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- PAT甲题题解-1016. Phone Bills (25)-模拟、排序
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- Angular(1)
1.设计原则 1.YAGNI 不要把未来需求引入当前工程 2.KISS keep it simple and stupid 语义化标记 合理注释 符合规定的命名 3.DRY(don't re ...
- SQL 之witn as语法
with as 是临时视图的语法:with qry_a as (select * from table_a )select * from qry_a ;
- 通过DOM节点操作来获取表单信息
这是之前突发奇想地用dom节点的关系来操作表单的故事.. 事情的经过是这样的,大概就是一个平台注册后有留言功能,管理员登录之后可以对这些留言进行回复.这个页面呢,就是通过foreach获取到数据库里的 ...
- Xcode取消某条警告
[Xcode取消某条警告] 像下面这样,把双引号“”内的内容替成实际的警告类型即可. #pragma clang diagnostic push #pragma clang diagnostic ...
- 'libxml/tree.h' file not found
看看Header Search Paths 为 '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Dev ...
- BVT & BAT & SVT
1. BVT(Build Verification Test) a. BVT概念 Build Verification test is a set of tests run on every new ...
- MoleHill Getting Started AGAL(转)
1.The OpCode This is what AGAL looks like: //vertex shader m44 op, va0, vc0 // pos to clipspace mov ...
- tinyxml学习4
tinyXML一款很优秀的操作C++类库,文件不大,但方法很丰富,和apache的Dom4j可以披靡啊!习惯了使用java类库的我看到这么丰富的c++类库,很高兴!它使用很简单,只需要拷贝几个文件到你 ...
- java web _BBS
在注册时用户输入用户名和密码不合格在旁边提示 在用户发言带有屏蔽字时应在旁边提示,但不影响其发送,只是在显示时屏蔽关键字
- mongodb根据字符长度作为条件查询
{ $where:"this.XXX.length==2" } 用$where条件查询,等号要用==.虽说$where查询可能效率不是很好,这只是我能想到的,有更好的方法欢迎指教