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特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- 更改RAC日志组
alter database add logfile thread 1 group 5 ('+DATA/idb/onlinelog/group5.log') size 256m;alter datab ...
- VGA逐行扫描控制器的Verilog建模
前言:因为VGA是一种模拟图像传输数据接口,所要将数字信号用DAC转换成模拟量.本文用的一款ADI公司高精度的视频IC,实则一款高带宽的视频DAC.因为VGA时序较为简单,并且网上的VGA驱动基本大同 ...
- Apache 配置HTTPS协议搭载SSL配置
在设置Apache + SSL之前, 需要做: 安装Apache, 请参见: Windows环境下Apache的安装与虚拟目录的配置, 下载安装Apache时请下载带有ssl版本的Apache ...
- 使用虚幻引擎中的C++导论(四-内存管理与垃圾回收)(终)
使用虚幻引擎中的C++导论(四)(终) 第一,这篇是我翻译的虚幻4官网的新手编程教程,原文传送门,有的翻译不太好,但大体意思差不多,请支持我O(∩_∩)O谢谢. 第二,某些细节操作,这篇文章省略了,如 ...
- myeclipse 导入JAVA项目
说白了.就是别人给你一份写好的文件你不会用是吧?新手都是这样的.很正常..这样.咱们一步一步的来.邮件项目工程栏,选择import,选择General,选择Existing Projects into ...
- javaweb学习第一天 debug
debug 断点: f5:step into f6:step over f7:step return drop to frame:跳到当前方法的的第一行 resume:跳到下一个断点 watch:观察 ...
- iOS 调用拍照、选择本地相册、上传功能---未完善。
1.新建viewController 拖入一个Button,添加点击事件,使用代理方法 <UIActionSheetDelegate,UIImagePickerControllerDelegat ...
- delegate事件绑定
为了代码的健壮性,绑定事件之前先解绑再进行绑定. var _$div = $("#id");_$div.undelegate("click mouseover mouse ...
- c#访问Oracle问题及解决方法
Q:访问oracle 查询条件带汉字结果集为空的问题 A:数据库连接字符串中加入Unicode=true即可. 如 <add key="DbConnectionString" ...
- 【C#】 一些不常用,很容易混淆的知识点
[C#] 一些不常用但很容易混淆的知识点 1. 访问修饰符 internal ,译为内部的, 在同一个程序集中可访问,它的内部是相对与程序集的,可不能想当然了 2. String.Compare 这个 ...