-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscalingrecipes.cpp
58 lines (43 loc) · 1.18 KB
/
scalingrecipes.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// kattis.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
void recipe(const int ingredients, double scale)
{
vector<string> names;
vector<double> percentages;
double main_int_gram_scale = 0;
for (int i = 0; i < ingredients; ++i)
{
double grams, percentage;
string name;
cin >> name >> grams >> percentage;
if (percentage == 100.0) main_int_gram_scale = grams * scale;
names.push_back(name);
percentages.push_back(percentage /= 100);
}
cout << fixed;
cout << setprecision(1);
for (int i = 0; i < ingredients; ++i)
{
cout << names.at(i) << " " << main_int_gram_scale * percentages.at(i) << endl;
}
}
int main()
{
int num_problems;
cin >> num_problems;
#
for (int i = 0; i < num_problems; ++i)
{
int num_ingredients;
double num_portions, num_required;
cin >> num_ingredients >> num_portions >> num_required;
cout << "Recipe # " << i+1 << endl;
recipe(num_ingredients, num_required / num_portions);
cout << "----------------------------------------" << endl;
}
}