image_2022-04-03_14-25-13.png
57 KB
#medium
#N1357. Apply Discount Every n Orders
problem link
#solution
#N1357. Apply Discount Every n Orders
problem link
#solution
class Cashier {
int count=0, order;
double discountProduct;
Map<Integer, Integer> map = new HashMap<>();
public Cashier(int n, int discount, int[] products, int[] prices) {
this.order=n;
this.discountProduct=1-(double)discount/100;
for(int i=0; i<prices.length; i++){
map.put(products[i], prices[i]);
}
}
public double getBill(int[] product, int[] amount) {
count++;
int total=0;
for(int i=0; i<amount.length; i++){
total+=map.get(product[i])*amount[i];
}
return count%order==0? total*discountProduct : total;
}
}