分析:

  模拟题,提交无数次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)的更多相关文章

  1. 1016. Phone Bills (25)——PAT (Advanced Level) Practise

    题目信息: 1016. Phone Bills (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A l ...

  2. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  3. 1016. Phone Bills (25) -vector排序(sort函数)

    题目如下: A long-distance telephone company charges its customers by the following rules: Making a long- ...

  4. 1016 Phone Bills (25)(25 point(s))

    problem A long-distance telephone company charges its customers by the following rules: Making a lon ...

  5. 1016 Phone Bills (25 分)

    A long-distance telephone company charges its customers by the following rules: Making a long-distan ...

  6. PAT A 1016. Phone Bills (25)【模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 ...

  7. 1016 Phone Bills (25分)

    复建的第一题 理解题意 读懂题目就是一个活,所以我们用观察输出法,可以看出来月份,以及时间和费用之间的关系. 定义过程 然后时间要用什么来记录呢?day hour minute 好麻烦呀..用字符串吧 ...

  8. PAT (Advanced Level) 1016. Phone Bills (25)

    简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  9. PAT甲题题解-1016. Phone Bills (25)-模拟、排序

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

随机推荐

  1. tony_nginx_02_URL重写

    location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的 ...

  2. Fighting Game

    感谢上外静中任淳同学提供   uses crt; label   h;         //h是重新开始游戏 const   y1=18;   y2=18;       //p1,p2的纵坐标 var ...

  3. VPS及LNMP(一)

    1.试用了搬瓦工.interserver.天翼云.网安互联之后,分别写下感受: 前两个是美国服务器,天翼云是国内服务器,网安互联是香港主机. a.搬瓦工非常便宜,512M的1年9.99刀,但是用了之后 ...

  4. 升级正版win10及保持yosemite双操

    因为有同事升级了正版的win10,心头长草了,本来x230的win7就是正版,现在win10可以免费升级,为何不做? 为此跑了2趟lenovo的维修站,诸多限制,最终决定自己搞定.据说,需要恢复到原厂 ...

  5. loadrunner 功能详解(一) - Run-time Settings

    1.General / Run Logic  Number of Iterations:说明的是反复循环的次数. 常境的时间中,如果时间设为5分钟,而实际上程序的运行只需要1分钟,而在这项中,选择的是 ...

  6. 埃及分数-IDA*

    Description 在古埃及,人们使用单位分数的和(形如1/a的, a是自然数)表示一切有理数.如:2/3=1/2+1/6,但不允许2/3=1/3+1/3,因为加数中有相同的.对于一个分数a/b, ...

  7. 关于ImageMagick出现无效参数(invalid parameter)的解决方法

    Windows 命令行 运行"convert logo.jpg  f:\parseWord\tmp\logo.png" 时显示 “无效参数(Invalid Parameter)” ...

  8. css之让文字在一定范围内显示,不超过固定的宽度和高度

  9. xtrabackup备份与恢复实践

    说明   xtrabackup  --percona 特点: 开源,在线备份innodb表 支持限速备份,避免对业务造成影响 支持流备 支持增量备份 支持备份文件压缩与加密 支持并行备份与恢复,速度快 ...

  10. empty isset array_key_exists 的区别

    empty: 参数为0或为NULL时(如上面列子),empty均返回TRUE,详细情况可以参见empty官方手册 isset: 参数为NULL时,返回FALSE,0与NULL在PHP中是有区别的,is ...