/* * @LastEditTime: 2026-11-30 12:55:38 */ classCashier { private: int n, th; double percentage; unordered_map<int, int> product2price; public: Cashier(int n, int discount, vector<int>& products, vector<int>& prices) { this->n = n; this->percentage = 1. * (100 - discount) / 100; for (size_t i = 0, n = products.size(); i < n; i++) { product2price[products[i]] = prices[i]; } th = 0; }
doublegetBill(vector<int> product, vector<int> amount){ int original = 0; for (size_t i = 0, n = product.size(); i < n; i++) { original += product2price[product[i]] * amount[i]; }
if (++th % n == 0) { return percentage * original; } return original; } };
/** * 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); */
publicCashier(int n, int discount, int[] products, int[] prices) { this.n = n; percentage = 1 - (double)discount / 100; p2p = newHashMap<>(); for (inti=0; i < products.length; i++) { p2p.put(products[i], prices[i]); } }
publicdoublegetBill(int[] product, int[] amount) { intprice=0; for (inti=0, n = product.length; i < n; i++) { price += p2p.get(product[i]) * amount[i]; } return ++th % n == 0 ? percentage * price : price; } }
/** * 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); */
/* * @LastEditTime: 2026-11-30 13:02:24 */ package main
type Cashier struct { products2prices map[int]int n, th int percentag float64 }
funcConstructor(n int, discount int, products []int, prices []int) Cashier { products2prices := make(map[int]int) for i, p := range products { products2prices[p] = prices[i] } return Cashier{ products2prices, n, 0, float64(100 - discount) / 100, } }
func(this *Cashier) GetBill(product []int, amount []int) float64 { price := 0 for i, p := range product { price += this.products2prices[p] * amount[i] } this.th++ if this.th % this.n == 0 { return this.percentag * float64(price) } returnfloat64(price) }
/** * Your Cashier object will be instantiated and called as such: * obj := Constructor(n, discount, products, prices); * param_1 := obj.GetBill(product,amount); */
/** * Your Cashier object will be instantiated and called as such: * let obj = Cashier::new(n, discount, products, prices); * let ret_1: f64 = obj.get_bill(product, amount); */