PAT_A1016#Phone Bills
Source:
Description:
A long-distance telephone company charges its customers by the following rules:
Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.
Input Specification:
Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.
The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.
The next line contains a positive number N (≤), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (
mm:dd:hh:mm), and the wordon-lineoroff-line.For each test case, all dates will be within a single month. Each
on-linerecord is paired with the chronologically next record for the same customer provided it is anoff-linerecord. Anyon-linerecords that are not paired with anoff-linerecord are ignored, as areoff-linerecords not paired with anon-linerecord. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.
Output Specification:
For each test case, you must print a phone bill for each customer.
Bills must be printed in alphabetical order of customers' names. For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (
dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.
Sample Input:
10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
10
CYLL 01:01:06:01 on-line
CYLL 01:28:16:05 off-line
CYJJ 01:01:07:00 off-line
CYLL 01:01:08:03 off-line
CYJJ 01:01:05:59 on-line
aaa 01:01:01:03 on-line
aaa 01:02:00:01 on-line
CYLL 01:28:15:41 on-line
aaa 01:05:02:24 on-line
aaa 01:04:23:59 off-line
Sample Output:
CYJJ 01
01:05:59 01:07:00 61 $12.10
Total amount: $12.10
CYLL 01
01:06:01 01:08:03 122 $24.40
28:15:41 28:16:05 24 $3.85
Total amount: $28.25
aaa 01
02:00:01 04:23:59 4318 $638.80
Total amount: $638.80
Keys:
- 模拟题
Code:
/*
Data: 2019-07-17 19:24:07
Problem: PAT_A1016#Phone Bills
AC: 53:32 题目大意:
统计月度话费账单
输入:
第一行给出,各小时的话费权重cent/minute
第二行给出,通话数N<=1e3
接下来N行,name,time,status(on/off)
输出:
打印各个用户的账单,姓名递增
name,month
start,end,time,costs
total amount
*/ #include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e3+,H=;
struct node
{
string name,status;
string time;
}info[M];
struct mode
{
int dd,hh,mm;
};
int n,w[H]; bool cmp(const node &a, const node &b)
{
if(a.name != b.name)
return a.name < b.name;
else
return a.time < b.time;
} mode Time(string s)
{
mode t;
t.dd = atoi(s.substr(,).c_str());
t.hh = atoi(s.substr(,).c_str());
t.mm = atoi(s.substr(,).c_str());
return t;
} int Pay(string s1, string s2, int &time, int &cost)
{
mode t1 = Time(s1);
mode t2 = Time(s2);
while(t1.dd!=t2.dd || t1.hh!=t2.hh || t1.mm!=t2.mm)
{
time++;
cost += w[t1.hh];
t1.mm++;
if(t1.mm==)
{
t1.mm=;
t1.hh++;
}
if(t1.hh==)
{
t1.hh=;
t1.dd++;
}
}
return cost;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif for(int i=; i<H; i++)
scanf("%d", &w[i]);
scanf("%d", &n);
for(int i=; i<n; i++)
cin >> info[i].name >> info[i].time >> info[i].status;
sort(info,info+n,cmp);
for(int i=; i<n; i++)
{
int valid=,bill=;
while(i<n && info[i-].name==info[i].name)
{
int cost=,time=;
if(info[i-].status=="on-line"&&info[i].status=="off-line")
{
if(!valid) cout << info[i].name << " " << info[].time.substr(,) << endl;
valid=;
bill += Pay(info[i-].time,info[i].time,time,cost);
cout << info[i-].time.substr() << " " << info[i].time.substr();
printf(" %d $%.2f\n", time,1.0*cost/100.0);
}
i++;
}
if(valid) printf("Total amount: $%.2f\n", 1.0*bill/100.0);
} return ;
}
PAT_A1016#Phone Bills的更多相关文章
- 【题解搬运】PAT_A1016 Phone Bills
从我原来的博客上搬运.原先blog作废. 题目 A long-distance telephone company charges its customers by the following rul ...
- PAT 1016. Phone Bills
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- Oracle Bills of Material and Engineering Application Program Interface (APIs)
In this Document Goal Solution 1. Sample Notes for BOM APIs 2. Datatypes used in these APIs ...
- 1016. Phone Bills (25) -vector排序(sort函数)
题目如下: A long-distance telephone company charges its customers by the following rules: Making a long- ...
- PAT A1016 Phone Bills (25 分)——排序,时序
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- A1016. Phone Bills
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- PAT 1016 Phone Bills[转载]
1016 Phone Bills (25)(25 分)提问 A long-distance telephone company charges its customers by the followi ...
- 1016 Phone Bills (25 分)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following rul ...
- 1016 Phone Bills (25)(25 point(s))
problem A long-distance telephone company charges its customers by the following rules: Making a lon ...
随机推荐
- java并发编程笔记(五)——线程安全策略
java并发编程笔记(五)--线程安全策略 不可变得对象 不可变对象需要满足的条件 对象创建以后其状态就不能修改 对象所有的域都是final类型 对象是正确创建的(在对象创建期间,this引用没有逸出 ...
- VC2008中将CString转换成const char*的一种有效方法
文章转载自http://blog.csdn.net/lanbing510/article/details/7425613 在Visual Studio 200X下,CString直接转换成const ...
- mysql 密码
http://www.cnblogs.com/jonsea/p/5510219.html character-set-server=utf8 mysql 修改密码: ALTER USER 'root' ...
- python_面向对象,类名称空间,对象名称空间,组合
创建一个类就会创建一个类的名称空间,用来存储类中定义的所有名字,这些名字称为类的属性 而类有两种属性:静态属性和动态属性 静态属性就是直接在类中定义的变量(字段) 动态属性就是定义在类中的方法 其中类 ...
- ArcGis 创建含孔洞面要素AO C#
IGeometryCollection geometryCollection = new PolygonClass(); IPointCollection pointCollection_Exteri ...
- Darknet YOLOv3 on Jetson Nano
推荐比较好的博客:https://ai4sig.org/2019/06/jetson-nano-darknet-yolov3/ 用的AlexeyAB的版本,并且给出了yolov3和tiny的效果对比. ...
- spring基于xml的事务控制
opm配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...
- shell script 学习
终于来到了shell脚本的学习,貌似很牛叉. shell script鸟叔解释:利用shell的功能写的一个program,使用纯文本文件,将一些shell语法和指令写在里面,搭配正则表示法,管线命令 ...
- fzu 1901 next+脑洞
题目大意: 给你一个字符串str,对于每个str长度为p的前缀,如果str[i]==str[p+i](p+i<len),那么我们认为它是一个periodic prefixs.求所有满足题意的前缀 ...
- 56. Map(双列集合)
在生活中有些数据是以映射关系存在的,也就是成对出现的,比如:老公 老婆(key-->value) 双列集合:-------------------| Map 如果是实现了Map接口的集合 ...