当前位置: 首页 > 工具软件 > Discount > 使用案例 >

1357. Apply Discount Every n Orders

司马宏茂
2023-12-01

类的实现,简单题,

class Cashier {
public:
    int now = 0;
    int N;
    int Discount;
    map<int, int> id2price;
    Cashier(int n, int discount, vector<int>& products, vector<int>& prices) {
        for(int i;i<prices.size();i++){
            id2price[products[i]] = prices[i];
        }
        N = n;
        Discount = discount;
    }
    
    double getBill(vector<int> product, vector<int> amount) {
        now ++; // 1
        double sum = 0.0;
        for(int i=0;i<product.size();i++){
            sum += double(id2price[product[i]])*double(amount[i]);
        }
        if (now%N==0){
            sum = sum - (Discount * sum) / 100.0;
        }
        return sum;
    }
};

/**
 * 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);
 */
 类似资料:

相关阅读

相关文章

相关问答