[leetcode]1357. 每隔 n 个顾客打折

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

class Cashier {
    int n, discount;
    unordered_map<int,int>hash;
    int cnt;
public:
    Cashier(int n, int discount, vector<int>& products, vector<int>& prices) {
        this->n = n;
        this->discount = discount;
        for(int i = 0; i < products.size(); i++)
        {
            hash[products[i]] = prices[i];
        }
        cnt = 0;
    }
    
    double getBill(vector<int> product, vector<int> amount) {
        double res = 0;
        cnt++;
        for(int i = 0; i < product.size(); i++)
        {
            res += hash[product[i]] *amount[i];
        }
        if(cnt == n)
        {
            res -= (discount*res/100);
            cnt = 0;
        }
        return res;
    }
};

/**
 * 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);
 */
发布了179 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40691051/article/details/104455548