塑身菜单

从现在开始,拟定属于你自己的健康饮食方案吧! 一份全新的健康饮食计划,将会使

你浑身充满活力。如果长时间坚持这样的饮食,那么不仅你患疾病的几率降低,而且还会比

预期寿命延长15 年。当然,随之而来的,还有你一直向往的好身材。假设供选择的菜单如

下:每份热量单位:大卡/100 克


假设供选择的菜单如下:每份热量单位:大卡/100 克

Boiled Fish with Pickled Cabbage and Chili 92

Sauted Sliced Pork with Pepper and Chili , Sichuan Style 231

Cold Noodles Sichuan Style 260

Fish Filets in Hot Chili Oil 239

Steamed Rice Rolls 196

Kung Pao Chicken 313

Hot and Sour Rice Noodles 144


Soybean Milk 92

Steamed Rice 31

Scrambled Egg with Scallion 81

Steamed Jiaozi 119

Sauted Sliced Pork with Black Fungus 143


Scrambled Egg with Leek 128

Steamed Bun Stuffed with Red Bean Paste 128

Yu-Shiang Shredded Pork (Sauted with Spicy Garlic Sauce) 134

Description

输入最大摄入热量值(要求:每份菜只能要一份)

Input

输出满足总摄入热量小于等于最大摄入热量值的菜品种类最多的组合

Output
1
150
Sample Input
1
2
Steamed Rice 31
Scrambled Egg with Scallion 81

以后处理这种题的时候不要看数据数据麻烦,要用数组存储,如果用if语句就太麻烦了。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct date
{
char name[200];
int col;
};
bool cmp(date a,date b)
{
if(a.col!=b.col)
return a.col<b.col;
else
return strcmp(a.name,b.name)<0;
}
int main()
{
struct date arr[15]={{"Boiled Fish with Pickled Cabbage and Chili",92},
{"Sauted Sliced Pork with Pepper and Chili , Sichuan Style",231},
{"Cold Noodles Sichuan Style",260},{"Fish Filets in Hot Chili Oil",239},{"Steamed Rice Rolls",196},
{"Kung Pao Chicken",313},{"Hot and Sour Rice Noodles",144},{"Soybean Milk",92},{"Steamed Rice",31},
{"Scrambled Egg with Scallion",81},{"Steamed Jiaozi",119},{"Sauted Sliced Pork with Black Fungus",143},
{"Scrambled Egg with Leek",128},{"Steamed Bun Stuffed with Red Bean Paste",128},
{"Yu-Shiang Shredded Pork (Sauted with Spicy Garlic Sauce)",134}};
sort(arr,arr+15,cmp);
int total;
while(scanf("%d",&total)!=EOF)
{
int i,j,sum=0;
for(i=0;i<15;i++)
{
sum=sum+arr[i].col;
if(sum>total)
break;
}
for(j=0;j<i;j++)
printf("%s %d\n",arr[j].name,arr[j].col);
}
return 0;
}
Sample Output
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值