【PAT甲级】1016 Phone Bills (25 分)(结构体排序)
题意:
输入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 分)(结构体排序)的更多相关文章
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- PAT甲级1016. Phone Bills
PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...
- PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...
- PAT A 1016. Phone Bills (25)【模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 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 ...
- 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 ...
随机推荐
- Python学习之Craps赌博游戏篇
在此先安利一波大佬的Python学习项目地址:https://github.com/jackfrued/Python-100-Days 这些天一直在看着大佬的项目学习Python,这是第五天循环学习完 ...
- mui 进度条 隐藏
官方提供的 mui(contanier).progressbar().hide(); 并未起作用,DOM是js动态添加的,结果无法隐藏.(越使用,mui 的坑越多,陆续记录中...) 后使用下面的方法 ...
- 解决linux乱码问题
echo "LANG="zh_CN.UTF-8" >> /etc/sysconfig/i18n yum -y install kde-l10n-Chinese ...
- eclipse好用的快捷键
eclipse一些增加工作效率的快捷键(部分自己添加) eclipse如何修改快捷键 1. shift + enter | ctrl + shift + enter 在下/上方增加空行 2. ctrl ...
- acwing练习
220. 最大公约数 给定整数N,求1<=x,y<=N且GCD(x,y)为素数的数对(x,y)有多少对. GCD(x,y)即求x,y的最大公约数. 输入格式 输入一个整数N 输出格式 输出 ...
- 高次arccos积分
\[\Large\displaystyle \int_0^{1} \frac{\arccos^4 \left(x^2\right)}{\sqrt{1-x^2}}\,\mathrm{d}x\] \(\L ...
- python 处理html文本的中文字符gbk转utf-8
#中文字符gbk转utf-8 def gbk2utf8(self,raw): rs=raw.encode('raw_unicode_escape') #转为机器识别字符串 s=repr(rs) ss= ...
- pip install cv2 安装报错
pip install cv2 安装报错是一个常见现象: ERROR: Could not find a version that satisfies the requirement cv2 (fro ...
- python中for循环中的循环变量
废话不多说,代码伺候: for i in range(3): print("hello") print(i) 运行结果如下: 从上面的例子可以看出,for循环里面的循环变量i作用域 ...
- Django 字段中 null 和 blank的区别
blank 设置为 True 时,字段可以为空 设置为 False 时,字段是必须填写的 默认为 False null 设置为 True 时,数据库的字段允许为NULL,而且表单中的空值将会被存储为N ...