题意:

输入24个正整数代表从0到23每个小时通话一分钟花费的美分。输入一个正整数N(<=1000),然后输入N组字符串,每个字符串包含客户的名字和通话的时刻以及打出或者挂断的状态。

按照字典序输出用户的名字,(每一段,按行输出)通话时长和花费,以及Total amount。

trick:

对于没打通的用户(没有花费),不要输出它的Total amount。(第1,2数据点答案错误原因)

AAAAAccepted code:

 #include<bits/stdc++.h>
using namespace std;
int a[];
typedef struct users{
string name;
int month,day,hour,minute,time;
string condition;
int flag;
};
users user[];
bool cmp(users a,users b){
if(a.name!=b.name)
return a.name<b.name;
else{
if(a.day!=b.day)
return a.day<b.day;
else if(a.hour!=b.hour)
return a.hour<b.hour;
else
return a.minute<b.minute;
}
}
map<string,double>mp;
int main(){
int all=;
for(int i=;i<;++i){
cin>>a[i];
all+=a[i];
}
int n;
cin>>n;
for(int i=;i<=n;++i){
cin>>user[i].name;
scanf("%d:%d:%d:%d ",&user[i].month,&user[i].day,&user[i].hour,&user[i].minute);
cin>>user[i].condition;
if(user[i].condition[]=='n')
user[i].flag=;
}
sort(user+,user++n,cmp);
string tmp=user[].name;
user[n+].name="sewage";
for(int i=;i<=n+;++i){
if(user[i].name!=tmp&&mp[tmp])
printf("Total amount: $%.2f\n",mp[tmp]);
tmp=user[i].name;
if(user[i].flag==&&user[i+].flag==&&user[i].name==user[i+].name){
if(!mp[user[i].name]){
cout<<user[i].name;
printf(" %02d\n",user[i].month);
}
printf("%02d:%02d:%02d %02d:%02d:%02d ",user[i].day,user[i].hour,user[i].minute,user[i+].day,user[i+].hour,user[i+].minute);
double sum=;
int mm=;
mm+=-user[i].minute;
sum=1.0*(-user[i].minute)*a[user[i].hour];
mm+=user[i+].minute;
sum+=1.0*user[i+].minute*a[user[i+].hour];
user[i].hour++;
for(int j=user[i].hour;j<;++j)
sum+=1.0*a[j]*,mm+=;
for(int j=;j<user[i+].hour;++j)
sum+=1.0*a[j]*,mm+=;
mm+=(user[i+].day-user[i].day-)*;
sum+=1.0*(user[i+].day-user[i].day-)*all*;
sum/=100.0;
printf("%d $%.2f\n",mm,sum);
mp[user[i].name]+=sum;
++i;
}
}
return ;
}

【PAT甲级】1016 Phone Bills (25 分)(结构体排序)的更多相关文章

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

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

  2. PAT 甲级 1028. List Sorting (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...

  3. PAT甲级1016. Phone Bills

    PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...

  4. PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...

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

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

  6. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  7. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  8. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  9. PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

    1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be ...

  10. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

    1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime ...

随机推荐

  1. python代码在linux终端中执行报错:Unable to init server: Could not connect: Connection refused

    python代码在linux终端中执行时报错: Unable to init server: Could not connect: Connection refused Unable to init ...

  2. Postman的使用和测试

    1.输入认证的IP,获取headers 2.输入用户名及密码 3.带着headers去访问网址 4.传参

  3. 01-Spring的概述

    Spring概述 ①Spring是一个开源框架 ②Spring为简化企业级开发而生,使用Spring开发可以将Bean对象,Dao组件对象,Service组件对象等交给Spring容器来管理,这样使得 ...

  4. layer.open中父页面向子页面传值

    1.咱先看图说话 父list.jsp 子operate.jsp实现的代码1 在父页面上完成对子页面的数据渲染 function setData(data) { var lay=layer.open({ ...

  5. Yii2.0 连接数据库

    打开数据库配置文件common\config\main-local.php

  6. 【PAT甲级】1089 Insert or Merge (25 分)(插入排序和归并排序)

    题意: 输入一个正整数N(<=100),接着输入两行N个整数,第一行表示初始序列,第二行表示经过一定程度的排序后的序列.输出这个序列是由插入排序或者归并排序得到的,并且下一行输出经过再一次排序操 ...

  7. 计算机二级-C语言-程序设计题-190118记录-通过数组和指针两种方式对字符串进行处理。

    //编写一个函数fun,比较两个字符串的长度,(不使用C语言提供的求字符串长度的函数),函数返回较长的字符串.若两个字符长度相同,则返回第一个字符串. //重难点:通过数组处理和通过指针进行处理的不同 ...

  8. Vue-项目搭建时的常用配置

    1.Vue静态资源存放的选择 assets: 编译过程中会被webpack处理理解为模块依赖,只支持相对路径的形式,assets放可能会变动的文件.static: 存放第三方文件的地方,不会被webp ...

  9. DataGrid 獲取 制定 row Col 單元格

    public static class DataGridHelper     {         /// <summary>                  /// Gets the v ...

  10. python学习HTML之CSS(2)

    1.边框的属性设置 PS:边框的高度和宽度可以采用百分比,但是高度方向的百分比基本无用,因为基数没定,参考没意义!! 2.内边距和外边距 3.在右下角添加一个“回顶部”的标签. <div> ...