1016 Phone Bills (25分)(一个字短!)

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分)

分析

将所有记录按照名字以及记录时间排序,将两条相邻的前后同名且前为on后为off的记录提取为一对用于计算通话时长的有效记录,并保存在map中对应的用户的记录中,最后遍历map计算每一对记录的时长、费用,以及总费用即可
注意时长以及费用的计算可以从00:00:00开始计算然后相减

代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
int d[24], n, momo, dd, hh, mm;
string id, con;
map<string, int> mon;
struct node {
 string iid;
 int tim, condi;
 node() {}
 node(string dd, int tt, int cc) :iid(dd), tim(tt), condi(cc) {}
};
vector<node> rcd;
bool cmp(node a, node b) {
 return (a.iid != b.iid) ? (a.iid < b.iid) : (a.tim < b.tim);
}
map<string, vector<pair<int, int> > >bill;
int getmoney(int t) {
 int s = 0, i = 0;
 while (t != 0) {
  if (t >= 60) {
   t -= 60;
   s += 60 * d[i % 24];
  }
  else{
   s += t * d[i % 24];
   t = 0;
  }
  ++i;
 }
 return s;
}
//另一种计算费用的方法
// int getmoney1(int t) {
//  int s = 0, dd = t / (24 * 60), hh = t / 60 % 24, mm = t % 60, ss = 0;
//  s += d[hh] * mm;
//  for (int i = 0; i < 24; ++i)ss += d[i];
//  s += ss * dd * 60;
//  for (int i = 0; i < hh; ++i)
//   s += d[i] * 60;
//  return s;
// }
int main() {
 for (int i = 0; i < 24; ++i)scanf("%d", &d[i]);
 scanf("%d", &n);
 while (--n >= 0) {
  cin >> id;
  scanf("%d:%d:%d:%d", &momo, &dd, &hh, &mm);
  mon[id] = momo;
  cin >> con;
  rcd.push_back(node(id, mm+hh*60+dd*24*60, con[1] == 'n'));
 }
 sort(rcd.begin(), rcd.end(), cmp);
 for (int i = 0; i < rcd.size() - 1; ++i)
  if (rcd[i].iid == rcd[i + 1].iid && rcd[i].condi == 1 && rcd[i + 1].condi == 0)
   bill[rcd[i].iid].push_back(pair<int, int>(rcd[i].tim, rcd[i + 1].tim));
 for (auto it : bill) {
  printf("%s %02d\n", it.first.c_str(), mon[it.first]);
  double s = 0;
  for (auto it1 : it.second) {
   int a = getmoney(it1.first), b = getmoney(it1.second);
                        //int a = getmoney1(it1.first), b = getmoney1(it1.second);
   double ss = (double)(b - a) / 100.0;
   printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", it1.first / (24 * 60), it1.first / 60 % 24, it1.first % 60, it1.second / (24 * 60), it1.second / 60 % 24, it1.second % 60, it1.second - it1.first, ss);
   s += ss;
  }
  printf("Total amount: $%.2f\n", s);
 }
 return 0;
}
PAT甲级 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. When a customer starts connecting a long-distance call, the ti 阅读详情

相关推荐

PAT A/甲级1016 Phone Bills 测试点123勘误

文章目录出错点关键点AC代码 题目链接 出错点 名字长度不超过20,则数组长度应至少为21,用以容纳‘\0’,卡测试点123。 输入数据至少有一对配对(…at least one call is well paired in the input…),则可能存在有用户没配对的情况,注意不要输出。即:将头(名字+月份)、尾(总费用)放在内层循环,或者至少要先判断一下。 代码的其他漏洞。毕竟这题的代码...

yoyostan的博客 2010

A1016(25)

很考察耐心的一道题,写起来也不是很复杂,耐心去做肯定是能写出来的啦 下面介绍一下auto的用法,比如,int或者double,我们可以写成,int i=0;double k=0.0,那么auto相当于我没有指代这个究竟是什么类型的,我可以写成,auto it=s.begin()什么的,这样我们在使用map之类的就很方便啦,至于map的用法,可以参考晴神算法笔记第六章的内容 题目大意是让你计算电话费...

coder_Kim的博客 284

MPC模型预测控制实战:从理论到代码实现(Python示例)

本文详细介绍了MPC模型预测控制的实战应用,从理论到Python代码实现。通过构建系统模型、预测方程、优化问题及约束处理,展示了如何实现一个完整的MPC控制器。文章还提供了水箱液位控制的应用案例,帮助读者掌握MPC在工业控制中的实际应用。

weixin_42653691的博客 461

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

cp0328的博客 3791

Langchain与Milvus集成中的pymilvus.exceptions.MilvusException: channel not found错误解析

本文深入解析了在Langchain与Milvus集成时常见的pymilvus.exceptions.MilvusException: channel not found错误。该错误通常由客户端配置错误、网络问题、服务端状态异常或版本不兼容导致。文章提供了从基础连通性测试到高级网络排查的完整故障排除指南,并针对本地Docker、远程服务器及Kubernetes等典型部署场景给出了具体解决方案,帮助开发者快速定位并修复这一连接层问题。

weixin_29229989的博客 217

SAP PP实战:MRP Area怎么用?手把手教你按产线、委外供应商拆分物料计划

本文详细解析了SAP PP模块中MRP Area的功能与应用,指导如何按产线、委外供应商拆分物料计划,实现精细化物料需求管理。通过实战案例展示MRP Area在减少计划冲突、提升库存准确率方面的显著效果,为制造业企业提供可落地的解决方案。

weixin_27015733的博客 432

A1016 Phone Bills (25 分)

1016 Phone Bills (25 分) 解题思路        这道题花了我很多时间,刷多了之后感觉相比树和图的题,这种细节比较多的题更难做一些,要想拿满分很不容易。        解这道题需要解决两个问题,一是怎么正确的找出一次通话的开始和结束的时间,解决的办法是把一个人的所有相关记录按照时间先后顺序排序,相...

LinxRds的博客 405

从零开始理解二极管限幅:5种典型电路设计及实际应用场景解析

本文系统解析了二极管限幅电路的五大经典拓扑,包括串联与并联型上下限幅及双向限幅。通过剖析其核心原理与二极管的单向导电性、正向压降特性,结合ADC输入保护、电源管理、音频处理等实际应用场景,提供了从器件选型到设计陷阱规避的完整实战指南,帮助工程师为信号构建可靠的“安全笼”。

2y3u4i5o6p的博客 1034

【注意点分析】1016 Phone Bills (25 分)

立志用最少的代码做最高效的表达 PAT甲级最优题解——>传送门 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 start

weixin_43899069的博客 5699

【OS】AUTOSAR架构下MCAL Modules软件分区问题分析

AUTOSAR架构下MCAL Modules软件分区问题分析

qq_36056498的博客 939

Flink CDC 中 StartupOptions 模式详解

Flink CDC 的 StartupOptions 模式用于指定作业启动时从源数据读取数据的起始位置,不同的模式适用于不同的业务场景,可满足多样化的数据处理需求,主要有 Initial 模式、Earliest 模式、Latest 模式、SpecificOffset 模式和 Timestamp 模式。

RodJohnsonDoctor的专栏 849

PAT 1016 Phone Bills (25 分)

PAT 1016 Phone Bills 今天给大家分享一道PAT甲级的小题,考察点: 模拟

Gnomeshgh的博客 364

基于YOLOv26的智能农业无人机巡检系统

本文提出了一种基于YOLOv26的智能农业无人机巡检系统。系统采用模块化设计,包含数据采集、预处理、目标检测、图像拼接、分析决策和部署控制六大核心模块。无人机搭载多光谱相机、RGB相机和热红外相机进行农田数据采集,通过YOLOv26实现作物病虫害、杂草及灌溉设备的检测。系统采用PyTorch、OpenCV等技术栈,支持无人机自动路径规划和多传感器数据采集,并包含数据增强和预处理功能。该系统可有效提升农业巡检效率,为精准农业提供智能化解决方案。

一键难忘的博客 809

1016 Phone Bills (25 分)(C++)

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_41562704的博客 704

42、多媒体与虚拟现实在艺术和影视领域的创新应用

本文探讨了多媒体与虚拟现实在艺术和影视领域的创新应用,涵盖三个典型案例:影视与人类学融合项目通过协作模式模糊作者与观众界限,推动文化文献的发展;交互式数字短片《分手》利用基于对象的广播技术探索个性化影视体验;威尼斯双年展瑞士馆4D项目则通过虚拟现实技术实现文化遗产的数字化展示。这些案例展示了技术在叙事、用户体验及文化保护中的深度应用,并展望了未来技术融合、个性化深化与文化遗产传承的发展趋势。

kappa的博客 115

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

1016 Phone Bills (25 分)(算时间差)

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 time of day wh...

树叶子的博客 625

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【1016】Phone Bills (25 分)

#include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<algorithm> #include<map> #include<vector> #inclu...

发现问题,并解决问题,批判性思维 704

android 蓝牙通讯demo

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

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

renly123的博客 334

1016 Phone Bills (25 分)

问题描述:给定每天每个时段的通话费用和每个人的打挂电话的记录,输出每个人的总费用和通话记录。 解题思路:用map将每个人与自己的通话记录关联起来,再对记录排序,计算费用,输出。计算费用,采用累积的方法,T1--T2的费用相当于从0-&gt;T2的费用减去0-&gt;T1的费用。 AC代码: #include&lt;iostream&gt; #include&lt;algorithm&gt;...

lianwaiyuwusheng的博客 703

PAT甲组1016.Phone Bills思路与注意点--补充《算法笔记》

A1016 题目链接 思路与注意点 数据结构:关于record的结构体(其中月日时分秒用5个int型记录) 由于账单是对每个进行统计的,因此需要对结构体进行按name排序,如果是同一个人,则按时间排序(时间按int类型记录方便比较) 题意要求只输出有效记录的用户账单,因此我们需要先找到拥有有效记录的用户,随后再进行记录的配对以及时间和话费的统计 计算话费和时长的方法:模拟天数与时分秒,对每一分钟进...

九筒的博客 404

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

韩江雪de 小屋 649

1016 Phone Bills(测试点分析)

分数 25全屏浏览切换布局作者 CHEN, Yue单位 浙江大学10CYJJ 01CYLL 01aaa 01。

m0_75262437的博客 930

1016 Phone Bills (25 分)

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 time of day wh...

chen_zan_yu_的博客 248

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

qq_39339575的博客 239
上一篇: 1015 Reversible Primes (20分)(一个字水)
下一篇: 1017 Queueing at Bank (25分)(一个字短!)
大了七八个
博客等级 码龄8年 2粉丝 30原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值