Source:

PAT A1016 Phone Bills (25 分)

Description:

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 (≤), 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-linerecords 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:

  1. 10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
  2. 10
  3. CYLL 01:01:06:01 on-line
  4. CYLL 01:28:16:05 off-line
  5. CYJJ 01:01:07:00 off-line
  6. CYLL 01:01:08:03 off-line
  7. CYJJ 01:01:05:59 on-line
  8. aaa 01:01:01:03 on-line
  9. aaa 01:02:00:01 on-line
  10. CYLL 01:28:15:41 on-line
  11. aaa 01:05:02:24 on-line
  12. aaa 01:04:23:59 off-line

Sample Output:

  1. CYJJ 01
  2. 01:05:59 01:07:00 61 $12.10
  3. Total amount: $12.10
  4. CYLL 01
  5. 01:06:01 01:08:03 122 $24.40
  6. 28:15:41 28:16:05 24 $3.85
  7. Total amount: $28.25
  8. aaa 01
  9. 02:00:01 04:23:59 4318 $638.80
  10. Total amount: $638.80

Keys:

  • 模拟题

Code:

  1. /*
  2. Data: 2019-07-17 19:24:07
  3. Problem: PAT_A1016#Phone Bills
  4. AC: 53:32
  5.  
  6. 题目大意:
  7. 统计月度话费账单
  8. 输入:
  9. 第一行给出,各小时的话费权重cent/minute
  10. 第二行给出,通话数N<=1e3
  11. 接下来N行,name,time,status(on/off)
  12. 输出:
  13. 打印各个用户的账单,姓名递增
  14. name,month
  15. start,end,time,costs
  16. total amount
  17. */
  18.  
  19. #include<cstdio>
  20. #include<vector>
  21. #include<string>
  22. #include<iostream>
  23. #include<algorithm>
  24. using namespace std;
  25. const int M=1e3+,H=;
  26. struct node
  27. {
  28. string name,status;
  29. string time;
  30. }info[M];
  31. struct mode
  32. {
  33. int dd,hh,mm;
  34. };
  35. int n,w[H];
  36.  
  37. bool cmp(const node &a, const node &b)
  38. {
  39. if(a.name != b.name)
  40. return a.name < b.name;
  41. else
  42. return a.time < b.time;
  43. }
  44.  
  45. mode Time(string s)
  46. {
  47. mode t;
  48. t.dd = atoi(s.substr(,).c_str());
  49. t.hh = atoi(s.substr(,).c_str());
  50. t.mm = atoi(s.substr(,).c_str());
  51. return t;
  52. }
  53.  
  54. int Pay(string s1, string s2, int &time, int &cost)
  55. {
  56. mode t1 = Time(s1);
  57. mode t2 = Time(s2);
  58. while(t1.dd!=t2.dd || t1.hh!=t2.hh || t1.mm!=t2.mm)
  59. {
  60. time++;
  61. cost += w[t1.hh];
  62. t1.mm++;
  63. if(t1.mm==)
  64. {
  65. t1.mm=;
  66. t1.hh++;
  67. }
  68. if(t1.hh==)
  69. {
  70. t1.hh=;
  71. t1.dd++;
  72. }
  73. }
  74. return cost;
  75. }
  76.  
  77. int main()
  78. {
  79. #ifdef ONLINE_JUDGE
  80. #else
  81. freopen("Test.txt", "r", stdin);
  82. #endif
  83.  
  84. for(int i=; i<H; i++)
  85. scanf("%d", &w[i]);
  86. scanf("%d", &n);
  87. for(int i=; i<n; i++)
  88. cin >> info[i].name >> info[i].time >> info[i].status;
  89. sort(info,info+n,cmp);
  90. for(int i=; i<n; i++)
  91. {
  92. int valid=,bill=;
  93. while(i<n && info[i-].name==info[i].name)
  94. {
  95. int cost=,time=;
  96. if(info[i-].status=="on-line"&&info[i].status=="off-line")
  97. {
  98. if(!valid) cout << info[i].name << " " << info[].time.substr(,) << endl;
  99. valid=;
  100. bill += Pay(info[i-].time,info[i].time,time,cost);
  101. cout << info[i-].time.substr() << " " << info[i].time.substr();
  102. printf(" %d $%.2f\n", time,1.0*cost/100.0);
  103. }
  104. i++;
  105. }
  106. if(valid) printf("Total amount: $%.2f\n", 1.0*bill/100.0);
  107. }
  108.  
  109. return ;
  110. }

PAT_A1016#Phone Bills的更多相关文章

  1. 【题解搬运】PAT_A1016 Phone Bills

    从我原来的博客上搬运.原先blog作废. 题目 A long-distance telephone company charges its customers by the following rul ...

  2. PAT 1016. Phone Bills

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

  3. Oracle Bills of Material and Engineering Application Program Interface (APIs)

    In this Document Goal   Solution   1. Sample Notes for BOM APIs   2. Datatypes used in these APIs   ...

  4. 1016. Phone Bills (25) -vector排序(sort函数)

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

  5. PAT A1016 Phone Bills (25 分)——排序,时序

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

  6. A1016. Phone Bills

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

  7. PAT 1016 Phone Bills[转载]

    1016 Phone Bills (25)(25 分)提问 A long-distance telephone company charges its customers by the followi ...

  8. 1016 Phone Bills (25 分)

    1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following rul ...

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

    problem A long-distance telephone company charges its customers by the following rules: Making a lon ...

随机推荐

  1. webpack中的url-loader

    使用url-loader引入图片,可以说它是file-loader的增强版 url-loader会把我们的图片使用base64的形式编码成另外一种字符串,网页是可以识别这种编码的东西的,这样的好处是, ...

  2. Redis Cluster 设置密码

    两种方式 1.修改配置文件 在每个节点的配置文件里面增加密码选项,一定要加上 masterauth,不然 Redirected 的时候会失败. masterauth redispassword req ...

  3. Nginx网络架构实战学习笔记(四):nginx连接memcached、第三方模块编译及一致性哈希应用

    文章目录 nginx连接memcached 第三方模块编译及一致性哈希应用 总结 nginx连接memcached 首先确保nginx能正常连接php location ~ \.php$ { root ...

  4. AutoFac控制反转 转载https://blog.csdn.net/u011301348/article/details/82256791

    一.AutoFac介绍 Autofac是.NET里IOC(Inversion of Control,控制反转)容器的一种,同类的框架还有Spring.NET,Unity,Castle等.可以通过NuG ...

  5. msf generate exec payload

    daniel@daniel-mint ~/msf/metasploit-framework $ ruby msfpayload windows/exec CMD=calc.exe N WARNING: ...

  6. PAT甲级——1147 Heaps【30】

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  7. 数据库全表扫描的SQL种类

    1.所查询的表的条件列没有索引: 2.需要返回所有的行: 3.对索引主列有条件限制,但是使用了函数,则Oracle 使用全表扫描,如: where  upper(city)=’TOKYO’; 这样的语 ...

  8. datetime中strptime用法

    import datetime day20 = datetime.datetime.strptime('2020-01-01 0:0:0', '%Y-%m-%d %H:%M:%S')nowdate = ...

  9. Ubuntu16.04+cuda9.0安装教程

    1.安装NVIDIA驱动 首先去官网(http://www.nvidia.cn/Download/index.aspx?lang=cn)查找适配自己电脑GPU的驱动,我的电脑驱动版本如下: 执行如下语 ...

  10. Shell 变量的分类