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特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- CSS布局概述
1.HTML5文档类型 由于Bootstrap使用了HTML5特定的HTML元素和CSS属性,所以使用Bootstrap的时候,所有的HTML文件都需要在其顶部引用HTML5的DOCTYPE属性,如下 ...
- jmeter的逻辑控制器
这篇是在网上找的,写的实在是比我写的具体得多,也没什么好补充的,拿来记录一下,方便以后查询,感激原作者!! JMeter中的Logic Controller分为两类:一类用来控制Test Plan执行 ...
- UVa10806 Dijkstra,Dijkstra-费用网络流
Problem, in short Given a weighed, undirected graph, find the shortest path from S to T and back wit ...
- Android IOS WebRTC 音视频开发总结(六八)-- Google: What's next for WebRTC
本文主要从用户,公司和技术角度分析美女视频直播这个行业,文章最早发表在我们的微信公众号上,支持原创,详见这里, 欢迎关注微信公众号blackerteam,更多详见www.rtc.help Justio ...
- 如何防止ElasticSearch集群出现脑裂现象(转)
原文:http://xingxiudong.com/2015/01/05/resolve-elasticsearch-split-brain/ 什么是“脑裂”现象? 由于某些节点的失效,部分节点的网络 ...
- 关于php Hash算法的一些整理总结
最近在公司内部的分享交流会上,有幸听到了鸟哥的关于php底层的一些算法的分享,虽然当时有些问题没有特别的明白,但是会后,查阅了各种各样的相关资料,对php的一些核心的hash算法有了进一步的理解和认识 ...
- XidianOJ 1120 Gold of Orz Pandas
题目描述 Orz Panda is addicted to one RPG game. To make his character stronger, he have to fulfil tasks ...
- 设置表格td宽度
CSS布局,表格宽度不听使唤的实例.想把表格第一例宽度设为20,其他自适应.但CSS中宽度是等宽的.只设这一行也不起作用.但是在实际应用中总是等宽处理,并不按照样式来走. XML/HTML代码 & ...
- linux C学习笔记02--共享内存(进程同步)
system V下3中进程同步:共享内存(shared memory),信号量(semaphore)和消息队列(message queue) 调试了下午,终于调通啦! 运行./c.out 输出共享内存 ...
- Brn系列网上商城数据库说明文档
单店版BrnShop_1.9.351数据字典:点击下载 多店版BrnMall_1.9.496数据字典:点击下载 有对网上商城程序设计感兴趣的朋友,欢迎加入QQ群:235274151,大家可以交流下!