分析:

  模拟题,提交无数次WA,注意几点:

  1.如果某人没有有效通话记录,则不输出该人的信息,在此WA15次,题目看了N遍也没出现啊。

  2.通话时间钱的计算:假设我们计算time1到time2的账单;

            (1)我们可以采用从起点(即00:00:00)开始计算,结果就是get_money(time2) - get_money(time1), 这样计算方便。

            (2)我们也可以采用从time1开始递增直到time2, 这样比较烦。

  3.有效的通话记录是指:如果某人的通话记录为1.on;2.on;3.off;,则其中1.on将被抛弃,匹配到2.on;3.off;

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <vector>
  7. #include <cctype>
  8. #include <stack>
  9. #include <map>
  10.  
  11. using namespace std;
  12.  
  13. int rate_structure[];
  14.  
  15. struct Person
  16. {
  17. string name;
  18. int month;
  19. int dd, hh, mm;
  20. int total;
  21. bool is_on_line;
  22. }person[];
  23.  
  24. int cmp(const Person &a, const Person &b)
  25. {
  26. if (a.name != b.name)
  27. return a.name < b.name;
  28. else return a.total < b.total;
  29. }
  30.  
  31. double get_money(int idx) // 得到钱
  32. {
  33. double money = ;
  34.  
  35. money += person[idx].dd * * rate_structure[];
  36. for (int i = ; i < person[idx].hh; i++)
  37. money += * rate_structure[i];
  38. money += person[idx].mm * rate_structure[person[idx].hh];
  39.  
  40. return money / ;
  41. }
  42.  
  43. bool should_output(int idx, int n) //判断某人的记录是否有有效记录
  44. {
  45. int pre = -;
  46. for (int i = idx; i < n; i++)
  47. {
  48. if (person[i].name == person[idx].name)
  49. {
  50. if (person[i].is_on_line == )
  51. pre = i;
  52. else if (person[i].is_on_line == )
  53. {
  54. if (pre != -) return ;
  55. }
  56. }
  57. else return ;
  58. }
  59. return ;
  60. }
  61.  
  62. void work(int n)
  63. {
  64. string tmp = person[].name;
  65. double sum = ;
  66. int pre = -; //记录off_line前一个的on_line
  67. bool flag = ;
  68.  
  69. if (should_output(, n))
  70. {
  71. cout << person[].name;
  72. printf(" %02d\n", person[].month);
  73. flag = ;
  74. }
  75. for (int i = ; i < n; i++)
  76. {
  77. if (person[i].name != tmp)
  78. {
  79. if (flag == )
  80. {
  81. printf("Total amount: $%.2lf\n", sum);
  82. flag = ;
  83. }
  84.  
  85. if (should_output(i, n))
  86. {
  87. cout << person[i].name;
  88. printf(" %02d\n", person[i].month);
  89. flag = ;
  90. }
  91. pre = -;
  92. sum = ;
  93. tmp = person[i].name;
  94. }
  95.  
  96. if (person[i].is_on_line == )
  97. pre = i;
  98. else if (person[i].is_on_line == )
  99. {
  100. if (pre != -)
  101. {
  102. printf("%02d:%02d:%02d ", person[pre].dd, person[pre].hh, person[pre].mm);
  103. printf("%02d:%02d:%02d ", person[i].dd, person[i].hh, person[i].mm);
  104. printf("%d ", person[i].total - person[pre].total);
  105.  
  106. double money = get_money(i) - get_money(pre);
  107. printf("$%.2lf\n", money);
  108. sum += money;
  109. pre = -;
  110. }
  111. }
  112. }
  113. if (flag == )
  114. printf("Total amount: $%.2lf\n", sum);
  115. }
  116.  
  117. int main()
  118. {
  119. int n;
  120. string status;
  121. while (scanf("%d", &rate_structure[]) != EOF)
  122. {
  123. rate_structure[] = rate_structure[]; //用rate_structure[24]存储0-23之和
  124. for (int i = ; i < ; i++)
  125. {
  126. scanf("%d", &rate_structure[i]);
  127. rate_structure[] += rate_structure[i];
  128. }
  129. scanf("%d", &n);
  130.  
  131. for (int i = ; i < n; i++)
  132. {
  133. cin >> person[i].name;
  134. scanf("%d:%d:%d:%d", &person[i].month, &person[i].dd,
  135. &person[i].hh, &person[i].mm);
  136. cin >> status;
  137.  
  138. person[i].total = person[i].dd * + person[i].hh * + person[i].mm;
  139. person[i].is_on_line = (status == "on-line"? : );
  140. }
  141.  
  142. sort(person, person + n, cmp);
  143.  
  144. work(n);
  145.  
  146. //print();
  147.  
  148. }
  149. return ;
  150. }

  

1016. Phone Bills (25)的更多相关文章

  1. 1016. Phone Bills (25)——PAT (Advanced Level) Practise

    题目信息: 1016. Phone Bills (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A l ...

  2. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

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

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

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

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

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

  5. 1016 Phone Bills (25 分)

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

  6. PAT A 1016. Phone Bills (25)【模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 ...

  7. 1016 Phone Bills (25分)

    复建的第一题 理解题意 读懂题目就是一个活,所以我们用观察输出法,可以看出来月份,以及时间和费用之间的关系. 定义过程 然后时间要用什么来记录呢?day hour minute 好麻烦呀..用字符串吧 ...

  8. PAT (Advanced Level) 1016. Phone Bills (25)

    简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  9. PAT甲题题解-1016. Phone Bills (25)-模拟、排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...

随机推荐

  1. eclipse下tomcat插件配置说明

  2. Handler基本概念

    Handler基本概念: Handler主要用于异步消息的处理:当发出一个消息之后,首先进入一个消息队列,发送消息的函数即刻返回,而另外一个部分逐个的在消息队列中将消息取出,然后对消息进行出来,就是发 ...

  3. 【javascript基础】2、函数

    前言 我在上一篇[javascript基础]基本概念中介绍了javascript的一些基本概念,多谢大家的阅读和意见,自己写的东西可以被大家阅读,真心高兴,刚开始发布的时候我一直盯着阅读人数,虽然知道 ...

  4. Android API Guides 学习笔记---Application Fundamentals(一)

    今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容. 1.      App ...

  5. 构造方法Constructor

    构造函数的名称与类名相同,没有返回值类型,主要用于在创建对象的时候进行一些初始化操作,如一个类中没有构造方法,java会默认给一个无参的构造方法

  6. 【knowledgebase】如何知道partition数

    对于调优和排错来说,查看一个RDD有多少个partition是非常有用的.常用的查看方法有如下几种: 1.通过SparkUI查看Task执行的partition数 当一个stage执行时,能通过Spa ...

  7. pytion学习1

    个人感觉学习一门新语言,简单的语法懂一点足矣.接下来就是编程.读懂别人程序的每一句,理解每一句的意义. #Filename:MyAddressBook.py import cPickle as p i ...

  8. 也说virtualbox下安装centos7

    以前一直在VMware Workstation下安装虚拟机系统,这几天由于电脑被别人使用误升级为win10,而导致原来的LNMP不能使用,查找原因在于即使是最新的VM12.1.1也只是支持win8而已 ...

  9. LIS检验系统,简介及主要特点

    简介 主要实现实验室设备的联机管理和信息传输以及发布,其联机共享范围小到单机版,大到医院之间或区域互联,都可以任意选择,按需升级.   主要特点 打报告不用输入姓名,报告处理轻松.高效.无差错 检查项 ...

  10. linux tr命令详解

    通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能.您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符.您也可以用它来除去重复 ...