类的实现,简单题,
class Cashier {
public:
int now = 0;
int N;
int Discount;
map<int, int> id2price;
Cashier(int n, int discount, vector<int>& products, vector<int>& prices) {
for(int i;i<prices.size();i++){
id2price[products[i]] = prices[i];
}
N = n;
Discount = discount;
}
double getBill(vector<int> product, vector<int> amount) {
now ++; // 1
double sum = 0.0;
for(int i=0;i<product.size();i++){
sum += double(id2price[product[i]])*double(amount[i]);
}
if (now%N==0){
sum = sum - (Discount * sum) / 100.0;
}
return sum;
}
};
/**
* 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);
*/