Advertisement
Vladislav_Bezruk

WAREHOUSE

Jul 9th, 2022
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. // ### task WAREHOUSE ###
  2.  
  3. #include <iostream>
  4.  
  5. #include <string>
  6.  
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. class Item
  12. {
  13.     string barcode;
  14.  
  15.     int fee;
  16.  
  17.     int hours;
  18.  
  19. public:
  20.  
  21.     Item(string barcode, int fee, int hours)
  22.     {
  23.         this->barcode = barcode;
  24.  
  25.         this->fee = fee;
  26.  
  27.         this->hours = hours;
  28.     }
  29.  
  30.     int calculate(int base_rate)
  31.     {
  32.         int res = 0;
  33.  
  34.         int d;
  35.  
  36.         switch (barcode[1])
  37.         {
  38.         case '1':
  39.             res = floor(hours / (24 * 30)) * fee;
  40.  
  41.             d = hours % (24 * 30);
  42.  
  43.             if (d > 0)
  44.             {
  45.                 res += d * base_rate;
  46.             }
  47.  
  48.             break;
  49.  
  50.         case '2':
  51.             res = floor(hours / (24)) * fee;
  52.  
  53.             d = hours % 24;
  54.  
  55.             if (d > 0)
  56.             {
  57.                 res += d * base_rate;
  58.             }
  59.  
  60.             break;
  61.  
  62.         case '3':
  63.             res = hours * fee;
  64.  
  65.             break;
  66.         }
  67.  
  68.         switch (barcode[0])
  69.         {
  70.         case '1':
  71.             break;
  72.  
  73.         case '2':
  74.             res *= 2;
  75.  
  76.             break;
  77.         }
  78.  
  79.         return res;
  80.     }
  81. };
  82.  
  83. int main()
  84. {
  85.     int base_rate;
  86.  
  87.     int cost = 0;
  88.  
  89.     string max_barcode;
  90.  
  91.     int max_cost = -1;
  92.  
  93.     cin >> base_rate;
  94.  
  95.     string barcode;
  96.  
  97.     int fee;
  98.  
  99.     int hours;
  100.  
  101.     while (cin >> barcode && barcode != "-1")
  102.     {
  103.         cin >> fee;
  104.  
  105.         cin >> hours;
  106.  
  107.         Item* item_p = new Item(barcode, fee, hours);
  108.  
  109.         int item_cost = item_p->calculate(base_rate);
  110.  
  111.         if (item_cost > max_cost)
  112.         {
  113.             max_cost = item_cost;
  114.  
  115.             max_barcode = barcode;
  116.         }
  117.  
  118.         cost += item_cost;
  119.     }
  120.  
  121.     cout << cost << " " << max_barcode;
  122.  
  123.     return 0;
  124. }
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement