码迷,mamicode.com
首页 > 其他好文 > 详细

1016. Phone Bills (25)

时间:2015-12-06 11:21:15      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:


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

 


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





1016. Phone Bills (25)

标签:

原文地址:http://www.cnblogs.com/zzandliz/p/5023059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!