代码拉取完成,页面将自动刷新
// Time: ctor: O(m), m is the number of all products
// getBill: O(p), p is the number of products to bill
// Space: O(m)
class Cashier {
public:
Cashier(int n, int discount, vector<int>& products, vector<int>& prices)
: n_{n}
, discount_{discount}
, curr_{0}
{
for (int i = 0; i < products.size(); ++i) {
lookup_[products[i]] = prices[i];
}
}
double getBill(vector<int> product, vector<int> amount) {
curr_ = (curr_ + 1) % n_;
double result = 0.0;
for (int i = 0; i < product.size(); ++i) {
result += lookup_[product[i]] * amount[i];
}
return curr_ == 0 ? result * (1.0 - discount_ / 100.0) : result;
}
private:
int n_;
int discount_;
int curr_;
unordered_map<int, int> lookup_;
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。