时间限制
400 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

去掉非法数据计算账单

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
来源: <http://www.patest.cn/contests/pat-a-practise/1016>

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<map>
  5. #include<string>
  6. #include<string.h>
  7. #include<stdio.h>
  8. #pragma warning(disable:4996)
  9. using namespace std;
  10. struct Record
  11. {
  12. char name[25];
  13. char time[12];
  14. char stat[9];
  15. int timeTrans;
  16. int statCode; //0 means online ;1 means offline
  17. };
  18. struct People{
  19. int startTime = -1;
  20. int endTime = -1;
  21. double amount = 0;
  22. vector<int> startTimeList;
  23. vector<int> endTimeList;
  24. vector<double> feeList;
  25. vector<int> callMinList;
  26. };
  27. vector<Record> r;
  28. vector<string> nameList;
  29. map < string, People > mp;
  30. int month;
  31. int feeRule[25] = { 0 };
  32. bool cmp(Record a, Record b){
  33. return a.timeTrans < b.timeTrans;
  34. }
  35. double CalcFee(int start, int end){
  36. int fee = 0;
  37. while (start<end)
  38. {
  39. fee += feeRule[start / 60 % 24];
  40. start++;
  41. }
  42. return 1.0*fee/100;
  43. }
  44. int main(void){
  45. //freopen("Text.txt", "r", stdin);
  46. for (int i = 0; i < 24; i++){
  47. cin >> feeRule[i];
  48. }
  49. int n;
  50. cin >> n;
  51. for (int i = 0; i < n; i++){
  52. Record temp;
  53. scanf("%s %s %s", temp.name, temp.time, temp.stat);
  54. if (temp.stat[1] == 'n')
  55. temp.statCode = 0;
  56. else
  57. temp.statCode = 1;
  58. int td, th, tm, ttime;
  59. sscanf(temp.time, "%d:%d:%d:%d", &month, &td, &th, &tm);
  60. ttime = td * 1440 + th * 60 + tm;
  61. temp.timeTrans = ttime;
  62. r.push_back(temp);
  63. }
  64. sort(r.begin(), r.end(), cmp);
  65. for (int i = 0; i < n; i++){
  66. string nameStr;
  67. int q = 0;
  68. while (r[i].name[q]!=0)
  69. {
  70. nameStr += r[i].name[q];
  71. q++;
  72. }
  73. if (r[i].statCode == 0){//online
  74. mp[nameStr].startTime = r[i].timeTrans;
  75. }
  76. else{
  77. if (mp[nameStr].startTime == -1){
  78. continue;
  79. }
  80. else{
  81. mp[nameStr].endTime = r[i].timeTrans;
  82. mp[nameStr].startTimeList.push_back(mp[nameStr].startTime);
  83. mp[nameStr].endTimeList.push_back(mp[nameStr].endTime);
  84. mp[nameStr].feeList.push_back(CalcFee(mp[nameStr].startTime,mp[nameStr].endTime));
  85. mp[nameStr].callMinList.push_back(mp[nameStr].endTime - mp[nameStr].startTime);
  86. mp[nameStr].startTime = -1;
  87. mp[nameStr].endTime = -1;
  88. }
  89. }
  90. }
  91. for (auto &k : mp){
  92. nameList.push_back(k.first);
  93. }
  94. sort(nameList.begin(), nameList.end());
  95. for (int i = 0; i < nameList.size(); i++){
  96. if (mp[nameList[i]].startTimeList.size() == 0)
  97. continue;
  98. cout << nameList[i] << " ";
  99. printf("%02d\n", month);
  100. double totalFee = 0;
  101. for (int j = 0; j < mp[nameList[i]].startTimeList.size(); j++){
  102. int sd = mp[nameList[i]].startTimeList[j] / 1440;
  103. int sh = mp[nameList[i]].startTimeList[j] / 60 % 24;
  104. int sm = mp[nameList[i]].startTimeList[j] % 60;
  105. int ed = mp[nameList[i]].endTimeList[j] / 1440;
  106. int eh = mp[nameList[i]].endTimeList[j] / 60 % 24;
  107. int em = mp[nameList[i]].endTimeList[j] % 60;
  108. printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", sd, sh, sm, ed, eh, em, mp[nameList[i]].callMinList[j], mp[nameList[i]].feeList[j]);
  109. totalFee += mp[nameList[i]].feeList[j];
  110. }
  111. printf("Total amount: $%.2f\n",totalFee);
  112. }
  113. return 0;
  114. }
来自为知笔记(Wiz)

转载于:https://www.cnblogs.com/zzandliz/p/5023059.html

1016. Phone Bills (25)相关推荐

  1. 1016 Phone Bills (25)(25 分)

    1 题目 2 解题思路 3 AC代码 4 总结 1 题目 A long-distance telephone company charges its customers by the followin ...

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

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 A long-distance telephone company charges its customers by the fo ...

  3. PAT 1016 Phone Bills (25分) 逻辑较为复杂 sort() + map

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

  4. 1016 Phone Bills (25 分) 【未完成】【难度: 中 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805493648703488

  5. 1016 Phone Bills (25分)

    这个题相对复杂一点,读题用了20分钟,然后就是疯狂写代码,其实这个主要是计算费用复杂一点,其他倒是还好,第一遍提交有测试点1,2没过,回头看了一眼代码觉得计算不可能出错,然后一分析就是测试点1,2很显 ...

  6. PAT甲级1016 Phone Bills :[C++题解]字符串处理(复杂题)(C语言格式化读入、输出很便利!!!)

    文章目录 题目分析 题目链接 题目分析 原题: 长途电话公司按以下规则向客户收费: 拨打长途电话每分钟要花费一定的费用,具体收费取决于拨打电话的时间. 客户开始拨打长途电话的时间将被记录,客户挂断电话 ...

  7. PAT (Advanced Level) 1016 Phone Bills(恶心模拟)

    题目链接:点击查看 题目大意:模拟电话收费规则: 每个时间段的收费不同,时间段分为:00:00-01:00,01:00-02:00诸如此类 最开始给出的单价是每分钟的单价 最后输出每个用户的电话费 题 ...

  8. PAT甲级 1016 Phone Bills(时间差)

    Link 题意: 远程电话的收费是按照每分钟来计费的,现在告诉你一天24小时中每分钟的收费标准,以及n条通话记录,试求出每个人该月的消费账单. 只有开始记录没有结束记录的通话不计费,反之亦然.保证所有 ...

  9. 1016 Phone Bills

    目录 概述: 一些小的注意点 AC代码 概述: 这道题是我迄今做出来的最复杂的一道PAT了,该题被归类到排序专题下,其实还涉及到大量的字符串处理等别的我暂时也说不出的知识点. 排序函数我写了两个,1是 ...

最新文章

  1. 2015.09.06 C++笔记
  2. const数组,strstr,strstr,
  3. php7.1安装mysqli扩展,centos php7 安装mysqli扩展心得
  4. 基于java SSM框架的旅游网站设计开发(含源文件)
  5. (23)FPGA面试题常用逻辑电平
  6. 聚类算法 距离矩阵_机器学习基础-层次聚类
  7. linux脚本能轮循吗,通过Linux定时任务实现定时轮询数据库及发送Http请求
  8. WPF ComboBox样式
  9. react-router-dom v4
  10. 当select查询为空
  11. C# DES 加解密
  12. 神州数码DC交换机VSF配置命令
  13. 经典的哲学家就餐问题
  14. Isilon上数据是如何存放的?
  15. android仿饿了么,Android 仿饿了么下拉Dialog
  16. 【LeetCode】72. Edit Distance
  17. 预算少怎么做ASO优化?
  18. 性能测试流程指南和工具推荐
  19. 深度学习跨层网络结构--特征融合
  20. Minecraft 1.16 简易高效的自动钓鱼脚本

热门文章

  1. 使用FortJs使用现代JavaScript开发Node.js
  2. uber_Uber是如何制成的
  3. 手机连接服务器数据库文件,手机连接服务器数据库文件夹
  4. mysql查询解析过程_MySQL查询执行过程详解
  5. oracle anbob,Tag Archives: oracle安装 | ANBOB
  6. mysql二进制日志管理_MYSQL二进制日志管理脚本
  7. 制作ui设计作品集要注意哪些
  8. Sublime Text保存文件时自动去掉行末空格
  9. php-fpm慢执行日志
  10. 安全攻防实战:使用winlogonhack获取系统密码