classCashier { unordered_map<int, int> m; int d; int nn; int index = 0; public: Cashier(int n, int discount, vector<int>& products, vector<int>& prices) { d = discount; nn = n; for (int i = 0; i < products.size(); ++i) { m[products[i]] = prices[i]; } index = 0; } doublegetBill(vector<int> product, vector<int> amount){ ++index; bool discount = false; if (index == nn) { index = 0; discount = true; } double ans = 0; for (int i = 0; i < product.size(); ++i) { ans += amount[i] * m[product[i]]; } if (discount) ans *= 1 - d / 100.0; return ans; } };
/** * Your Cashier object will be instantiated and called as such: * Cashier* obj = new Cashier(n, discount, products, prices); * double param_1 = obj->getBill(product,amount); */
1358. Number of Substrings Containing All Three Characters