Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- #include <utility>
- #include <map>
- #include <cmath>
- #include <fstream>
- struct Product {
- public:
- std::string name = "";
- int price = 0;
- long count_in_pack = 0;
- long biology_count = 0;
- double pr = 0, f = 0, ch = 0, fv = 0;
- long long total_count = 0;
- long pcs = 0;
- bool show = true;
- };
- struct Dish {
- public:
- std::string name;
- int people_to_eat;
- // In minimal units
- std::map<std::string, long> products;
- double pr = 0, f = 0, ch = 0, fv = 0;
- };
- long l_to_ml(int l) {
- return l * 1000;
- }
- long kd_to_g(int kg) {
- return kg * 1000;
- }
- long tense_to_cnt(int tense) {
- return tense * 10;
- }
- int main() {
- std::map<std::string, Dish> dishes;
- std::map<std::string, Product> products;
- int dishes_cnt;
- // std::ifstream fin("input.txt");
- auto &input_stream = std::cin;
- input_stream >> dishes_cnt;
- for (int i = 0; i < dishes_cnt; ++i) {
- Dish dish;
- std::string dish_name;
- input_stream >> dish_name;
- dish.name = std::move(dish_name);
- int friends_num;
- input_stream >> friends_num;
- dish.people_to_eat = friends_num;
- // Saving dish data
- int products_num;
- input_stream >> products_num;
- for (int j = 0; j < products_num; ++j) {
- std::string product_name;
- input_stream >> product_name;
- int product_count;
- input_stream >> product_count;
- std::string unit;
- input_stream >> unit;
- if (unit == "kg") {
- dish.products.emplace(product_name, kd_to_g(product_count));
- } else if (unit == "l") {
- dish.products.emplace(product_name, l_to_ml(product_count));
- } else if (unit == "tens") {
- dish.products.emplace(product_name, tense_to_cnt(product_count));
- } else {
- dish.products.emplace(product_name, product_count);
- }
- // Creating product, saving its in-dish data
- }
- dishes.emplace(dish.name, dish);
- }
- int shop_catalog_len;
- input_stream >> shop_catalog_len;
- for (int i = 0; i < shop_catalog_len; ++i) {
- Product p;
- std::string product_name;
- input_stream >> product_name;
- p.name = std::move(product_name);
- int price;
- input_stream >> price;
- p.price = price;
- int product_count_in_pack;
- input_stream >> product_count_in_pack;
- std::string unit;
- input_stream >> unit;
- if (unit == "kg") {
- p.count_in_pack = kd_to_g(product_count_in_pack);
- } else if (unit == "l") {
- p.count_in_pack = l_to_ml(product_count_in_pack);
- } else if (unit == "tens") {
- p.count_in_pack = tense_to_cnt(product_count_in_pack);
- } else {
- p.count_in_pack = product_count_in_pack;
- }
- products.emplace(p.name, p);
- // Saving data into price list
- }
- int biology_catalog_len;
- input_stream >> biology_catalog_len;
- for (int i = 0; i < biology_catalog_len; ++i) {
- std::string product_name;
- input_stream >> product_name;
- auto &p = products[product_name];
- int product_count;
- input_stream >> product_count;
- std::string unit;
- input_stream >> unit;
- if (unit == "kg") {
- p.biology_count = kd_to_g(product_count);
- } else if (unit == "l") {
- p.biology_count = l_to_ml(product_count);
- } else if (unit == "tens") {
- p.biology_count = tense_to_cnt(product_count);
- } else {
- p.biology_count = product_count;
- }
- double pr, f, ch, fv;
- input_stream >> pr >> f >> ch >> fv;
- p.pr = pr;
- p.f = f;
- p.ch = ch;
- p.fv = fv;
- // Saving biology data
- }
- for (auto &d : dishes) {
- Dish &d_ref = d.second;
- for (auto &p : d_ref.products) {
- auto &p_name = p.first;
- auto &p_data = products[p_name];
- p_data.total_count += p.second * d_ref.people_to_eat;
- if (p_data.biology_count != 0) {
- d_ref.pr += p_data.pr * ((double) p.second / (double) p_data.biology_count);
- d_ref.ch += p_data.ch * ((double) p.second / (double) p_data.biology_count);
- d_ref.f += p_data.f * ((double) p.second / (double) p_data.biology_count);
- d_ref.fv += p_data.fv * ((double) p.second / (double) p_data.biology_count);
- }
- }
- }
- long long total_price = 0;
- for (auto &p : products) {
- if (p.second.count_in_pack == 0) {
- p.second.show = false;
- }
- p.second.pcs = std::ceil((double) p.second.total_count / (double) p.second.count_in_pack);
- total_price += p.second.price * p.second.pcs;
- }
- std::cout << total_price << '\n';
- for (auto &p : products) {
- if (p.second.show == false) {
- continue;
- }
- std::cout << p.first << ' ' << p.second.pcs << '\n';
- }
- for (auto &d : dishes) {
- std::cout << d.first << ' ' << d.second.pr << ' ' << d.second.f << ' ' << d.second.ch << ' ' << d.second.fv << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement