Advertisement
shchuko

VasyaHappyBirthday

Jan 16th, 2020
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <utility>
  5. #include <map>
  6. #include <cmath>
  7. #include <fstream>
  8.  
  9.  
  10. struct Product {
  11. public:
  12.     std::string name = "";
  13.     int price = 0;
  14.     long count_in_pack = 0;
  15.     long biology_count = 0;
  16.  
  17.     double pr = 0, f = 0, ch = 0, fv = 0;
  18.  
  19.     long long total_count = 0;
  20.     long pcs = 0;
  21.     bool show = true;
  22. };
  23.  
  24.  
  25. struct Dish {
  26. public:
  27.     std::string name;
  28.     int people_to_eat;
  29.  
  30.     // In minimal units
  31.     std::map<std::string, long> products;
  32.     double pr = 0, f = 0, ch = 0, fv = 0;
  33.  
  34. };
  35.  
  36. long l_to_ml(int l) {
  37.     return l * 1000;
  38. }
  39.  
  40. long kd_to_g(int kg) {
  41.     return kg * 1000;
  42. }
  43.  
  44. long tense_to_cnt(int tense) {
  45.     return tense * 10;
  46. }
  47.  
  48.  
  49. int main() {
  50.  
  51.     std::map<std::string, Dish> dishes;
  52.     std::map<std::string, Product> products;
  53.  
  54.  
  55.     int dishes_cnt;
  56. //    std::ifstream fin("input.txt");
  57.     auto &input_stream = std::cin;
  58.     input_stream >> dishes_cnt;
  59.  
  60.     for (int i = 0; i < dishes_cnt; ++i) {
  61.         Dish dish;
  62.         std::string dish_name;
  63.         input_stream >> dish_name;
  64.         dish.name = std::move(dish_name);
  65.  
  66.         int friends_num;
  67.         input_stream >> friends_num;
  68.         dish.people_to_eat = friends_num;
  69.  
  70.         // Saving dish data
  71.         int products_num;
  72.         input_stream >> products_num;
  73.  
  74.         for (int j = 0; j < products_num; ++j) {
  75.             std::string product_name;
  76.             input_stream >> product_name;
  77.             int product_count;
  78.             input_stream >> product_count;
  79.  
  80.             std::string unit;
  81.             input_stream >> unit;
  82.  
  83.             if (unit == "kg") {
  84.                 dish.products.emplace(product_name, kd_to_g(product_count));
  85.             } else if (unit == "l") {
  86.                 dish.products.emplace(product_name, l_to_ml(product_count));
  87.             } else if (unit == "tens") {
  88.                 dish.products.emplace(product_name, tense_to_cnt(product_count));
  89.             } else {
  90.                 dish.products.emplace(product_name, product_count);
  91.             }
  92.  
  93.             // Creating product, saving its in-dish data
  94.         }
  95.         dishes.emplace(dish.name, dish);
  96.  
  97.     }
  98.  
  99.     int shop_catalog_len;
  100.     input_stream >> shop_catalog_len;
  101.  
  102.     for (int i = 0; i < shop_catalog_len; ++i) {
  103.         Product p;
  104.  
  105.         std::string product_name;
  106.         input_stream >> product_name;
  107.  
  108.         p.name = std::move(product_name);
  109.  
  110.         int price;
  111.         input_stream >> price;
  112.         p.price = price;
  113.  
  114.         int product_count_in_pack;
  115.         input_stream >> product_count_in_pack;
  116.  
  117.         std::string unit;
  118.         input_stream >> unit;
  119.  
  120.         if (unit == "kg") {
  121.             p.count_in_pack = kd_to_g(product_count_in_pack);
  122.         } else if (unit == "l") {
  123.             p.count_in_pack = l_to_ml(product_count_in_pack);
  124.         } else if (unit == "tens") {
  125.             p.count_in_pack = tense_to_cnt(product_count_in_pack);
  126.         } else {
  127.             p.count_in_pack = product_count_in_pack;
  128.         }
  129.         products.emplace(p.name, p);
  130.         // Saving data into price list
  131.     }
  132.  
  133.     int biology_catalog_len;
  134.     input_stream >> biology_catalog_len;
  135.  
  136.     for (int i = 0; i < biology_catalog_len; ++i) {
  137.         std::string product_name;
  138.         input_stream >> product_name;
  139.         auto &p = products[product_name];
  140.  
  141.  
  142.  
  143.         int product_count;
  144.         input_stream >> product_count;
  145.  
  146.         std::string unit;
  147.         input_stream >> unit;
  148.  
  149.         if (unit == "kg") {
  150.             p.biology_count = kd_to_g(product_count);
  151.         } else if (unit == "l") {
  152.             p.biology_count = l_to_ml(product_count);
  153.         } else if (unit == "tens") {
  154.             p.biology_count = tense_to_cnt(product_count);
  155.         } else {
  156.             p.biology_count = product_count;
  157.         }
  158.  
  159.         double pr, f, ch, fv;
  160.         input_stream >> pr >> f >> ch >> fv;
  161.         p.pr = pr;
  162.         p.f = f;
  163.         p.ch = ch;
  164.         p.fv = fv;
  165.         // Saving biology data
  166.     }
  167.  
  168.  
  169.     for (auto &d : dishes) {
  170.         Dish &d_ref = d.second;
  171.  
  172.         for (auto &p : d_ref.products) {
  173.             auto &p_name = p.first;
  174.             auto &p_data = products[p_name];
  175.  
  176.             p_data.total_count += p.second * d_ref.people_to_eat;
  177.             if (p_data.biology_count != 0) {
  178.                 d_ref.pr += p_data.pr * ((double) p.second / (double) p_data.biology_count);
  179.                 d_ref.ch += p_data.ch * ((double) p.second / (double) p_data.biology_count);
  180.                 d_ref.f += p_data.f * ((double) p.second / (double) p_data.biology_count);
  181.                 d_ref.fv += p_data.fv * ((double) p.second / (double) p_data.biology_count);
  182.             }
  183.         }
  184.     }
  185.  
  186.     long long total_price = 0;
  187.     for (auto &p : products) {
  188.         if (p.second.count_in_pack == 0) {
  189.          p.second.show = false;
  190.         }
  191.         p.second.pcs = std::ceil((double) p.second.total_count / (double) p.second.count_in_pack);
  192.         total_price += p.second.price * p.second.pcs;
  193.     }
  194.  
  195.  
  196.     std::cout << total_price << '\n';
  197.  
  198.     for (auto &p : products) {
  199.         if (p.second.show == false) {
  200.             continue;
  201.         }
  202.         std::cout << p.first << ' ' << p.second.pcs << '\n';
  203.     }
  204.  
  205.     for (auto &d : dishes) {
  206.         std::cout << d.first << ' ' << d.second.pr << ' ' <<  d.second.f << ' ' << d.second.ch << ' ' << d.second.fv << '\n';
  207.     }
  208.  
  209.  
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement