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-line
oroff-line
.For each test case, all dates will be within a single month. Each
on-line
record is paired with the chronologically next record for the same customer provided it is anoff-line
record. Anyon-line
records that are not paired with anoff-line
record are ignored, as areoff-line
records not paired with anon-line
record. 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 ...
随机推荐
- PHP-版本问题
PHP 5.3 以下版本 无法用下标直接取得函数返回的数组 eg: $val_0 = explode(',', $val)[0]//报错 #要改成: $exploded_val = explode(' ...
- 创建线程方法&守护线程
创建线程方法1. class mythread extends Thread{ 重写run方法 } mythread m=new mythread () 启动:m.start() 创建线程方法2. c ...
- Jmeter 5.1命令行执行bat文件
一.编写run_jmeter,bat @echo off::设置参数::参考命令:jmeter -n -t d:\123.jmx -l result.jtl -e -o d:\report\repor ...
- 基于nodejs的一个实时markdown转html工具小程序
1.版本一 - 1.1`npm install marked --save` 安装markdwon转html的包.- 1.2 使用watchFile监视 markdown文件 /** * Create ...
- Rust <10>:宏导出、导入
源 crate 中使用 #[macro_export] 属性标记的宏,调用者可在导入此 crate 时添加 #[macro_use] 属性使用. 没有 #[macro_export] 的宏,外部不可见 ...
- 调用WPF程序时传入参数
http://blog.csdn.net/martin_cheng/article/details/41351013 http://blog.csdn.net/libby1984/article/de ...
- python2和python3中int整型数据的不同之处
python2中的除法,结果为整型数字(int型),例如 10/5=2,10/3=3,小数位向下取整 python3中的除法,结果为浮点型数字(float型)结果小数位最多保留16位小数
- Arcpy 将要素类添加到当前工作窗口(内容列表)
test1layer=arcpy.mapping.Layer( folder+"\\"+"result.shp") mxd = arcpy.mapping.Ma ...
- java获取网页源代码并写入本地文件中
import java.io.*; import java.net.*; public class URLDemo { public static void main(String args[]){ ...
- 【转】网站SEO优化中网站的三大标签指的是什么?
对于很多刚刚接触SEO的新手朋友来说,会经常听到别人提及网站的三大标签.那么,具体什么是网站的三大标签呢?其实网站的三大标签指的就是title.keywords.description,通俗一点也可以 ...