diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /discount_n_orders.cpp | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'discount_n_orders.cpp')
-rw-r--r-- | discount_n_orders.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/discount_n_orders.cpp b/discount_n_orders.cpp new file mode 100644 index 0000000..a76d21e --- /dev/null +++ b/discount_n_orders.cpp @@ -0,0 +1,27 @@ +#include "leetcode.h" + +class Cashier { +public: + Cashier(int n, int discount, vector<int> &products, vector<int> &prices) { + count = 0, mod = n, pct = (100.0 - discount) / 100.0; + for (int i = 0; i < products.size(); ++i) + tags[products[i]] = prices[i]; + } + double getBill(vector<int> product, vector<int> amount) { + count++; + double ans(0.0); + for (int i = 0; i < product.size(); ++i) + ans += tags[product[i]] * amount[i]; + return count % mod ? ans : ans * pct; + } + +private: + unordered_map<int, int> tags; + int count, mod; + double pct; +}; + +int main() { + Cashier *obj = new Cashier(n, discount, products, prices); + double param_1 = obj->getBill(product, amount); +} |