forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipes.cpp
45 lines (40 loc) · 1.16 KB
/
recipes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
struct ingredient {
string name;
double weight;
double percent;
};
int main() {
int recipes;
cin >> recipes;
for(int i = 0; i < recipes; i++) {
int ingredients, portion, portionDesired;
cin >> ingredients >> portion >> portionDesired;
double scale;
vector<ingredient> ings;
double relevantWeight;
scale = double(portionDesired) / double(portion);
for(int j = 0; j < ingredients; j++) {
string n;
double w, p;
cin >> n >> w >> p;
if(p == 100.0) {
relevantWeight = w;
}
ingredient ing = {n, w, p};
ings.push_back(ing);
}
cout << "Recipe # " << i + 1 << endl;
for(int j = 0; j < ingredients; j++) {
double print = relevantWeight * (ings[j].percent / 100) * scale;
cout << ings[j].name << " ";
cout << fixed << setprecision(1) << print << endl;
}
cout << "----------------------------------------" << endl;
}
}