Source:

PAT A1016 Phone Bills (25 分)

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 word on-line or off-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 an off-line record. Any on-linerecords that are not paired with an off-line record are ignored, as are off-line records not paired with an on-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的更多相关文章

  1. 【题解搬运】PAT_A1016 Phone Bills

    从我原来的博客上搬运.原先blog作废. 题目 A long-distance telephone company charges its customers by the following rul ...

  2. PAT 1016. Phone Bills

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

  3. 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   ...

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

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

  5. PAT A1016 Phone Bills (25 分)——排序,时序

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

  6. A1016. Phone Bills

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

  7. PAT 1016 Phone Bills[转载]

    1016 Phone Bills (25)(25 分)提问 A long-distance telephone company charges its customers by the followi ...

  8. 1016 Phone Bills (25 分)

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

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

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

随机推荐

  1. 262K Color

    262K色=2^18=262144色. 320*240是指屏幕分辨率. 你可以理解为一块黑板,这款黑板宽是3.2M,长是2.4米,以1cm为最小单位,整个黑板被分为320*240个小格子,这个小格子里 ...

  2. 搭建Linux C语言开发环境

    1.操作系统 Windows操作系统:windows 7 and windows 10 2.开发工具和编译工具 开发工具:notpad++ 和 vim 编译工具:Cygwin64 Terminal 3 ...

  3. js匿名函数测试

    js匿名函数测试 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  4. HP Server BIOS实验报告

    原文链接http://www.hpiss.com/3924.html 注意:红色字体为HP手册中查找到的资源,及个人感觉应该注意的一些信息,个人翻译的也为红字体,网络中自行查找到的资源,以及询问各位师 ...

  5. UCML 原生Android中嵌入Cordova Webview

    Android实现在当前进程打开网页可以将Cordova中的WebView嵌入Android项目中,实现简单,不需要自己实现,所以掌握如何嵌入WebView对项目快速开发很有帮助 官方也有这方面的教程 ...

  6. grep 后加单引号、双引号和不加引号的区别

    请尊重版权,原文地址:https://blog.csdn.net/cupidove/article/details/8783968 单引号: 可以说是所见即所得:即将单引号内的内容原样输出,或者描述为 ...

  7. upc组队赛12 Janitor Troubles【求最大四边形面积】

    Janitor Troubles Problem Description While working a night shift at the university as a janitor, you ...

  8. vue实现轮播效果

    vue实现轮播效果 效果如下:(不好意思,图有点大:) 功能:点击左侧图片,右侧出现相应的图片:同时左侧边框变颜色. 代码如下:(也可以直接下载文件) <!DOCTYPE html> &l ...

  9. Cocos2d-x之Node

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 节点是cocosd-x游戏引擎中的重要元素,是其他重要游戏元素的基类,例如,场景Scene,图层Layer,菜单Menu和精灵sprite ...

  10. mybatis之增删改

    前面三小节内容主要是针对查询操作进行讲解,现在对mybatis增删改进行演示. 由于每次建立工程比较复杂,可以参考第一节:mybatis入门来搭建一个简单的工程,然后来测试本节内容. 1.增 1.新增 ...