1016. Phone Bills (25)

news/2024/7/7 18:28:54

时间限制
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


http://lihuaxi.xjx100.cn/news/270010.html

相关文章

万字长文综述目标检测领域,你要的都在这里

来源 | AI专栏&#xff08;ID: pursue-Y-future&#xff09;目标检测是计算机视觉中的一个重要问题&#xff0c;近年来传统检测方法已难以满足人们对目标检测效果的要求&#xff0c;随着深度学习在图像分类任务上取得巨大进展&#xff0c;基于深度学习的目标检测算法逐渐成为主…

火星无人机「机智号」代码开源,1.2w人参与贡献

视学算法报道作者&#xff1a;小舟、陈萍火星上的一小步&#xff0c;人类的一大步。当地时间 19 日 NASA 宣布在毅力号的「注视」下&#xff0c;机智号&#xff08;Ingenuity&#xff09;无人直升机成功完成了火星上的首次飞行&#xff0c;并完成 3 米高度悬停 30 秒的高难度动…

qtp9.2测试java_QTP的使用举例说明

1.QTP介绍QTP是quicktest Professional的简称&#xff0c;是一种自动测试工具。使用QTP的目的是想用它来执行重复的手动测试&#xff0c;主要是用于回归测试和测试同一软件的新版本。因此你在测试前要考虑好如何对应用程序进行测试&#xff0c;例如要测试那些功能、操作步骤、输…

linux下查看nginx,apache,mysql,php的编译参数

有时候nginx&#xff0c;apache&#xff0c;mysql&#xff0c;php编译完了想看看编译参数可以用以下方法 nginx编译参数&#xff1a; #/usr/local/nginx/sbin/nginx -V nginx version: nginx/0.6.32 built by gcc 4.1.2 20071124 (Red Hat 4.1.2-42) configure arguments: --us…

基于OpenCV 的车牌识别

点击上方“小白学视觉”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达车牌识别是一种图像处理技术&#xff0c;用于识别不同车辆。这项技术被广泛用于各种安全检测中。现在让我一起基于OpenCV编写Python代码来完成这一任务。车牌识别的相关步…

可见面判别算法---可见面判别算法的分类

2019独角兽企业重金招聘Python工程师标准>>> 转载于:https://my.oschina.net/liyangke/blog/2875781

讨论:Service层需要接口吗?

点击上方蓝色“方志朋”&#xff0c;选择“设为星标”回复“666”获取独家整理的学习资料&#xff01;链接&#xff1a;toutiao.com/i6882356844245975563前几天刷头条又刷到了「Service层和Dao层真的有必要每个类都加上接口吗&#xff1f;」这个问题&#xff0c;之前简单回答了…

Linux(Centos)之安装Java JDK及注意事项

1.准备工作 a.因为Java JDK区分32位和64位系统&#xff0c;所以在安装之前必须先要判断以下我们的Centos系统为多少位系统&#xff0c;命令如下&#xff1a; uname -a解释&#xff1a;如果有x86_64就是64位的&#xff0c;没有就是32位的。后面是X686或X86_64则内核是64位的&…