leetcode 1357. Apply Discount Every n Orders 每隔 n 个顾客打折-耗时100
Problem: 1357. Apply Discount Every n Orders 每隔 n 个顾客打折耗时100%用哈希表存储每种产品对应的价格prod然后计算总和即可Codeclass Cashier { public: int prod[201], nn, cnt 0; double disc; Cashier(int n, int discount, vectorint products, vectorint prices) { memset(prod, 0, sizeof(prod)); for(int i 0; i products.size(); i) { prod[products[i]] prices[i]; } nn n; disc (100.0 - discount) / (double)100.0; } double getBill(vectorint product, vectorint amount) { cnt; int total 0; int m product.size(); for(int i 0; i m; i) total prod[product[i]] * amount[i]; if(cnt % nn 0) return (double)total * disc; return total; } }; /** * 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); */
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2410025.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!