Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ### task WAREHOUSE ###
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- class Item
- {
- string barcode;
- int fee;
- int hours;
- public:
- Item(string barcode, int fee, int hours)
- {
- this->barcode = barcode;
- this->fee = fee;
- this->hours = hours;
- }
- int calculate(int base_rate)
- {
- int res = 0;
- int d;
- switch (barcode[1])
- {
- case '1':
- res = floor(hours / (24 * 30)) * fee;
- d = hours % (24 * 30);
- if (d > 0)
- {
- res += d * base_rate;
- }
- break;
- case '2':
- res = floor(hours / (24)) * fee;
- d = hours % 24;
- if (d > 0)
- {
- res += d * base_rate;
- }
- break;
- case '3':
- res = hours * fee;
- break;
- }
- switch (barcode[0])
- {
- case '1':
- break;
- case '2':
- res *= 2;
- break;
- }
- return res;
- }
- };
- int main()
- {
- int base_rate;
- int cost = 0;
- string max_barcode;
- int max_cost = -1;
- cin >> base_rate;
- string barcode;
- int fee;
- int hours;
- while (cin >> barcode && barcode != "-1")
- {
- cin >> fee;
- cin >> hours;
- Item* item_p = new Item(barcode, fee, hours);
- int item_cost = item_p->calculate(base_rate);
- if (item_cost > max_cost)
- {
- max_cost = item_cost;
- max_barcode = barcode;
- }
- cost += item_cost;
- }
- cout << cost << " " << max_barcode;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement