From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/discount_n_orders.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 other/discount_n_orders.cpp (limited to 'other/discount_n_orders.cpp') diff --git a/other/discount_n_orders.cpp b/other/discount_n_orders.cpp new file mode 100644 index 0000000..a76d21e --- /dev/null +++ b/other/discount_n_orders.cpp @@ -0,0 +1,27 @@ +#include "leetcode.h" + +class Cashier { +public: + Cashier(int n, int discount, vector &products, vector &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 product, vector 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 tags; + int count, mod; + double pct; +}; + +int main() { + Cashier *obj = new Cashier(n, discount, products, prices); + double param_1 = obj->getBill(product, amount); +} -- cgit v1.2.3