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特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- eclipse下tomcat插件配置说明
- Handler基本概念
Handler基本概念: Handler主要用于异步消息的处理:当发出一个消息之后,首先进入一个消息队列,发送消息的函数即刻返回,而另外一个部分逐个的在消息队列中将消息取出,然后对消息进行出来,就是发 ...
- 【javascript基础】2、函数
前言 我在上一篇[javascript基础]基本概念中介绍了javascript的一些基本概念,多谢大家的阅读和意见,自己写的东西可以被大家阅读,真心高兴,刚开始发布的时候我一直盯着阅读人数,虽然知道 ...
- Android API Guides 学习笔记---Application Fundamentals(一)
今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容. 1. App ...
- 构造方法Constructor
构造函数的名称与类名相同,没有返回值类型,主要用于在创建对象的时候进行一些初始化操作,如一个类中没有构造方法,java会默认给一个无参的构造方法
- 【knowledgebase】如何知道partition数
对于调优和排错来说,查看一个RDD有多少个partition是非常有用的.常用的查看方法有如下几种: 1.通过SparkUI查看Task执行的partition数 当一个stage执行时,能通过Spa ...
- pytion学习1
个人感觉学习一门新语言,简单的语法懂一点足矣.接下来就是编程.读懂别人程序的每一句,理解每一句的意义. #Filename:MyAddressBook.py import cPickle as p i ...
- 也说virtualbox下安装centos7
以前一直在VMware Workstation下安装虚拟机系统,这几天由于电脑被别人使用误升级为win10,而导致原来的LNMP不能使用,查找原因在于即使是最新的VM12.1.1也只是支持win8而已 ...
- LIS检验系统,简介及主要特点
简介 主要实现实验室设备的联机管理和信息传输以及发布,其联机共享范围小到单机版,大到医院之间或区域互联,都可以任意选择,按需升级. 主要特点 打报告不用输入姓名,报告处理轻松.高效.无差错 检查项 ...
- linux tr命令详解
通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能.您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符.您也可以用它来除去重复 ...