1016 Phone Bills (25 point(s))

1016 Phone Bills (25)(25 分) 1 题目 2 解题思路 3 AC代码 4 总结 1 题目 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 ... 阅读详情

1016 Phone Bills (25 point(s))

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 (≤1000), 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-line records 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

复杂模拟。注意STL的使用、有效记录判断等。

思路:

1. 对于每一条记录,采用结构体record来记录,注意基于时间重载运算符。

2.  对每一位用户分别记录他/她的通话记录,考虑到要按照时间排序,可以利用set本身的排序,使用map<string,set<record> > mp存储。

3. 输入完成后,对于每一位用户的通话记录,判断哪些是有效的(注意迭代器的用法),同时计算分钟数、价格、总价格等。特别注意bill()分别按照每个小时不一样的标准(cents/minute)来计算单笔订单价格。

同类型题:1095 Cars on Campus (30 point(s))

#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
double price[24];//美元/分钟 
double dayPrice=0.0;
struct record{
	int month,day,hour,min,time;string status;
	bool operator < (const record &other) const{
		return time<other.time;
	}
	record(int mon,int d,int h,int m,int t,string s):month(mon),day(d),hour(h),min(m),time(t),status(s){}
};
double bill(int day,int hour,int min){//到1日0时0分的费用 
	double sum = min*price[hour];
	for(int i=0;i<hour;i++) sum+=(price[i]*60);
	return sum+(day-1)*dayPrice*60;
}
map<string,set<record> > mp; 
int main(void){
	for(int i=0;i<24;i++){
		cin>>price[i];
		price[i]=price[i]/100.00;
		dayPrice+=price[i];
	}
	int N;cin>>N;
	string name,status;int mon,day,hour,min;
	for(int i=0;i<N;i++){
		cin>>name;
		scanf("%d:%d:%d:%d",&mon,&day,&hour,&min);
		cin>>status;
		int time = min+hour*60+day*24*60;
		mp[name].insert(record(mon,day,hour,min,time,status));
	}
	map<string,set<record> >::iterator i;
	for(i = mp.begin();i!=mp.end();i++){
		set<record>::iterator j=(i->second).begin();
		set<record>::iterator jnext=(i->second).begin();
		jnext++; 
		bool output = false;
		double sumBill = 0.0;
		for(;j!=(i->second).end()&&jnext!=(i->second).end();j++,jnext++){
			if(j->status=="on-line"&&jnext->status=="off-line"){
				if(!output){
					printf("%s %02d\n",(i->first).c_str(),j->month);
					output = true;	
				}
				printf("%02d:%02d:%02d ",j->day,j->hour,j->min);
				printf("%02d:%02d:%02d ",jnext->day,jnext->hour,jnext->min);
				double thisBill = bill(jnext->day,jnext->hour,jnext->min) - bill(j->day,j->hour,j->min);
				printf("%d $%.2f\n",jnext->time-j->time,thisBill);
				sumBill += thisBill;
			}
		}
		if(output){
			printf("Total amount: $%.2f\n",sumBill);
		}
	}
	return 0;
}

 详细思路:https://blog.youkuaiyun.com/richenyunqi/article/details/79307384

STM32F103VET6实战:用W25Q64外部Flash实现Bootloader+Application双备份(含完整代码解析) 本文详细介绍了基于STM32F103VET6微控制器和W25Q64外部Flash实现Bootloader+Application双备份固件升级的完整方案。通过精心设计的Flash分区策略、可靠的Bootloader程序以及包含双重校验和自动回滚机制的升级流程,有效解决了远程升级过程中断电导致设备变砖的风险,确保了工业嵌入式系统的高可靠性与稳定性。 阅读详情

相关推荐

PADS VX2.7学习记录05-PADS Layout设计文件Gerber等输出整理

在“PDF Document”栏中,依次选中除REF-TOP和REF-BOT之外的文件,单击图标,将其余PDF Document文件进行删除,如图所示。然后单击【生成PDF】按钮,即可创建一份PDF格式的位号图。

tianpu2320959696的博客 1026

1016 Phone Bills (25 point(s))

题解 STL的简单应用。水题一只。   #include&lt;iostream&gt; #include&lt;map&gt; #include&lt;vector&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; using namespace std; const int MAXN = 25; const int MAXM ...

徐伯莱 322

Qt5.12.12安卓开发环境搭建:Windows下避开SDK版本坑的保姆级教程

本文提供Qt5.12.12在Windows下搭建Android开发环境的详细教程,重点解决SDK版本兼容性问题,特别是cmdline-tools与JDK8的匹配陷阱。通过精准选择组件版本、手动配置路径和修复常见错误,帮助开发者高效完成环境配置,适用于Qt跨平台移动开发。

weixin_33737774的博客 542

PAT 1016 Phone Bills (25 分)

1016 Phone Bills (25 分) 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...

peanWang的博客 360

Vue 10分钟入门VR全景显示 基于photo-sphere-viewer

文章目录前言一、引入photo-sphere-viewer?二、使用步骤1.引入库2.声明容器3.内容加载4.全部代码总结 前言 由于工作的需求,要实现全景图片的展示与预览,本来以为会是一个很难的内容,没想到使用现成的组件photo-sphere-viewer就可以轻松实现,上手只需要10分钟! 一、引入photo-sphere-viewer? 可以直接通过npm进行引入 npm install photo-sphere-viewer 二、使用步骤 1.引入库 photo-sphere-viewer

YIGE_MO的博客 5867

信息传输仿真:卫星通信系统仿真_(12).卫星通信系统仿真软件介绍

卫星通信系统仿真软件是进行卫星通信系统设计和性能优化的重要工具。通过这些软件,用户可以模拟和分析各种通信场景,验证不同的通信协议和算法,优化系统参数和配置。本节介绍了 MATLAB Simulink、NS-3、OPNET 和 SystemVue 的基本功能、特点和配置方法,希望对读者在选择和使用仿真软件时提供参考。在实际应用中,建议根据项目需求和团队能力,综合考虑选择合适的仿真软件。

2401_87715305的博客 1281

1016 Phone Bills (25 分)思路、 难点分析、用例易错点

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

qq_32691667的博客 1380

YOLOv9原创自研:卷积魔改 | 一种新颖的风车形卷积(PConv)融合注意力机制,加强微弱小目标检测能力

为了进一步提升小目标检测能力,风车形卷积(PConv)融合注意力机制进一步提升小目标检测能力

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 364

1016 Phone Bills (PAT Advanced) 坑点

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

I`m Angry! 721

OpenClaw一人公司落地案例:本地商家营销智能体月赚3万的秘密

角色:本地商家营销专家## 核心目标为商家生成高转化率的抖音营销策略,最大化 ROI。## 输入数据- 商家名称: "XX奶茶店"- 过去 30 天视频播放量: 12,000- 客单价: 28 元- 竞品平均播放量: 15,000- 市场趋势: rising## 策略生成规则1. **内容类型**:根据客单价推荐- < 30 元:美食探店 + 优惠券- > 30 元:场景化故事 + 会员权益2. **发布时间**:根据历史数据- 18:00-20:00 高峰期。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 543

【unity游戏开发入门到精通——UGUI】UI控件 —— Image图像控件

【unity游戏开发入门到精通——UGUI】UI控件 —— Image图像控件

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2359

1016. Phone Bills (25)

这题我感觉略复杂,hold不住,直接上浅蓝大神的代码。 #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int INF = 0x7FFFFFFF; const int maxn =

Aden的专栏 341

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

1016 Phone Bills (25 point(s))

1016 Phone Bills (25 point(s)) 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 conne

专栏 138

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

1016 Phone Bills (25 point(s)) - C语言 PAT 甲级

设计思路: * 输入数据,先按照客户名排序,再按照时间排序 * 遍历数据,前后客户名相同且状态分别为 on-line 和 off-line,为合格数据

有三只土豆 228

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

problem 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 ma...

weixin_30505225的博客 104

PTA甲级-1016 Phone Bills (25point(s)) (电话账单)

首先,先贴柳神的博客 https://www.liuchuo.net/ 这是地址 想要刷好PTA,强烈推荐柳神的博客,和算法笔记 题目原文 A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount...

Huangpengyu123的博客 366

PAT (Advanced Level) Practice 1016 Phone Bills (25 point(s))

题目:PAT A 1016 题目大意 首先输入24整数,表示在一天中24个小时的某个时辰打电话的费率。(美分/每分钟)。 接下来有n条记录。每条记录的格式如下:用户名,MM:dd:HH:mm(分别表示月:天:时:分)。以及一个类型表示接通on-line和挂断off-line。 题目需要按照用户名的字典序输出每个用户的账单。输出的格式为 用户名 月份 接通时间1 挂断时间1 通话时长1 费用1 接通时间2 挂断时间2 通话时长2 费用2 总计费用 首先本人感觉最难理解的部分是费用的计算。参考了别人的费用计算

helloful的博客 143

每日两道算法题-|Day14 of PAT----|1016 Phone Bills (25point(s))--|结构体排序以及Map映射使用--|详解

1016 Phone Bills (25point(s)) 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 da...

weixin_43661154的博客 244

1016 Phone Bills (25point(s)

1016 Phone Bills (25point(s)) 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 connecti

佳迪斯的博客 190

1016 Phone Bills (25 分) JAVA

题意: (1)排序题,但是细节很复杂。对于ID,按照字母表排序;而每个ID中的所有通话,按照日期从小到大排。 (2)用TreeMap来存储<String,ArrayList<Record>>来存储,一个ID对应一个列表,列表里存储ID的所有通话记录并排好序。而TreeMap里面可以自己写一个Comparator按ID排序 (3)同一个ID的排序完毕的列表里,相邻的on-line和off-line记为一次通话记录。 (4)对于每次通话,封装成一个Record对象,除了存储i..

LangWeiXian_的博客 339

【PAT甲级】1016 Phone Bills (25 分)

1016 Phone Bills 题目描述 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 t...

初见还是重逢的博客 394

[PAT]1016. Phone Bills (25)@Java

1016. Phone Bills (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-distance telephone company charges its

zjkC050818的博客 512

1016 Phone Bills (25)(25 points) (cj)

1016 Phone Bills (25)(25 point(s))Questions A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending o...

Cute_jinx的博客 273

PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)...

1016Phone Bills(25分) 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 tim...

蔡军帅 369

1016. Phone Bills

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

qq285966121的博客 182
上一篇: 1043 Is It a Binary Search Tree (25 point(s))
下一篇: 1040 Longest Symmetric String (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值