Problem

9/11

馅饼

Problem

修改程序,使其解决以下问题。

彼佳非常喜欢有各种馅料的馅饼,至于吃哪一种并不重要。有一次,彼佳饿极了,走进自助餐店,看到有卖土豆、卷心菜和米饭的馅饼。 Petya 想买尽可能多的馅饼,但问题是出售的馅饼数量与 Petya 的金额一样有限。
 
帮助 Petya 确定他可以购买的最大馅饼数量。
 
输入
第一行包含数字P1P2P 3< /sub> –分别用土豆、卷心菜和米饭做馅饼的成本。第二行定义值N1N2N3 –出售的匹配馅饼的数量。第三行包含数字 R – Petya 有多少钱。输入的所有数字都是不超过1000的正整数。
 
输出
打印一个整数——问题的答案。

 
例子
<头> <正文>
# 输入 输出
1
5 3 8
2 6 4
23
7
Write the program below
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct patty {
    int cost, count;

    patty() {}
};

bool cmp(patty first, patty second)
 {   
}

vector<patty>pattyArray(3, patty());
int money;
int number;
int answer;

int main() {
    for(int i = 0; i < 3; i++)
        cin >> pattyArray.at(i).cost;
    for (int i = 0; i < 3; i++)
        cin >> pattyArray.at(i).count;

    sort(pattyArray.begin(), pattyArray.end(), cmp);

    cin >> money;

    for (int i = 0; i < 3; i++) {
        number = min(money / pattyArray.at(i).cost, pattyArray.at(i).count);
        answer += number;
        money -= number * pattyArray.at(i).cost;
    }

    cout << answer;
}   

     

Program check result

To check the solution of the problem, you need to register or log in!