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 ...
随机推荐
- how to catch error in make error message
make 2>&1 | grep error -C 10 -n
- Rust <4>:所有权、借用、切片
tips:栈内存分配大小固定,访问时不需要额外的寻址动作,故其速度快于堆内存分配与访问. rust 所有权规则: 每一个值在任意时刻都有且只有唯一一个所有者 当所有者离开作用域时,这个值将被丢弃 所有 ...
- 08、python的基础--->文件操作
注:用btyes方式的一般都是在“非文字类的(比如图片)” 1.文件的读取 >>>第1种 #绝对路径 s = open('E:\天气.txt', mode='r', encoding ...
- 推荐几个顶级的IT技术公众号,坐稳了!
提升自我的路很多,学习是其中最为捷径的一条.丰富的知识提升的不仅仅是你的阅历,更能彰显你的气质,正如古人云:"文质彬彬是君子." 今天为大家整理了10个公众号,分别为多领域,多角度 ...
- js保留两位小数的方法
js保留两位小数的方法如下 1.toFixed()方法 需注意,保留两位小数,将数值类型的数据改变成了字符串类型 2.Math.floor(),不四舍五入 ,向下取整 注意,不改变数据类型 3.字符串 ...
- python--知识小结和集合
知识小结 一. = 表示赋值 ==表示比较值的大小 is 比较内存地址 二. 数字小数据池:在-5~256之内,id在电脑里是一样的 字符串id一样要求: ①:不能有特殊字符 ②:s(一个单字符)*2 ...
- 案例- CSS 三角加强
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 导入C文件Xcode出现Could not build module 'Foundation'错误
#ifdef __OBJC__ #import <Foundation/Foundation.h> #import "UIImageView+WebCache.h" # ...
- 2018-8-10-win10-uwp-DataContext-
title author date CreateTime categories win10 uwp DataContext lindexi 2018-08-10 19:16:53 +0800 2018 ...
- Redis 管道(pipeline)