【结构体排序+STL容器】HDU-1070 Milk
发布日期:2021-06-29 04:32:34 浏览次数:2 分类:技术文章

本文共 788 字,大约阅读时间需要 2 分钟。

在这里插入图片描述

在这里插入图片描述

注解

1、结构体排序。注意perprice,每天的价格,必须是double类型。

2、STL vector的用法要熟悉。
3、超过1000mL的只喝五天,每天的价格要按总价除以5天来计算,因为最多只能喝5天。
4、如果每天的价格相同,要输出总容量大的。

代码

#include 
#include
#include
#include
using namespace std;struct Milk {
string name; double perPrice; double vol;};int compare(Milk a, Milk b) {
if(a.perPrice!=b.perPrice) {
return a.perPrice
b.vol; }}int main() {
int T; cin>>T; for(int i=0; i
>N; vector
v; v.clear(); for(int j=0; j
>m.name; int price; cin>>price; int vol; cin>>m.vol; if(m.vol>=1000) { m.perPrice = price / 5.0; v.push_back(m); } else if(m.vol>=200) { m.perPrice = price / floor(m.vol/200); v.push_back(m); } } sort(v.begin(), v.end(), compare); cout<
<

结果

在这里插入图片描述

转载地址:https://blog.csdn.net/zhanggirlzhangboy/article/details/103480958 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:【字符串+map+iterator】HDU-1075 What Are You Talking About
下一篇:【模拟+字符串处理】HDU-1073 Online Judge

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月28日 17时35分50秒