package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/apply-discount-every-n-orders/
 */
public class Problem1357 {
    private static class Cashier {
        private final int n;
        private final int discount;
        private Map</* product= */ Integer, /* price= */ Integer> prices = new HashMap<>();
        private int count = 0;

        public Cashier(int n, int discount, int[] products, int[] prices) {
            this.n = n;
            this.discount = discount;
            for (int i = 0; i < products.length; i++) {
                this.prices.put(products[i], prices[i]);
            }
        }

        public double getBill(int[] product, int[] amount) {
            count++;
            double total = 0;
            for (int i = 0; i < product.length; i++) {
                double price = prices.get(product[i]);
                if (count % 3 == 0) {
                    price = (prices.get(product[i]) * discount) / 100;
                }
                total += price * amount[i];
            }
            return total;
        }
    }

    public static void main(String[] args) {
        Cashier cashier = new Cashier(
            3, 50, new int[]{1, 2, 3, 4, 5, 6, 7}, new int[]{100, 200, 300, 400, 300, 200, 100});
        System.out.println(cashier.getBill(new int[]{1, 2}, new int[]{1, 2})); // 500
        System.out.println(cashier.getBill(new int[]{3, 7}, new int[]{10, 10})); // 4000
        System.out.println(cashier.getBill(new int[]{1, 2, 3, 4, 5, 6, 7}, new int[]{1, 1, 1, 1, 1, 1, 1})); // 800
        System.out.println(cashier.getBill(new int[]{4}, new int[]{10})); // 4000
        System.out.println(cashier.getBill(new int[]{7, 3}, new int[]{10, 10})); // 4000
        System.out.println(cashier.getBill(new int[]{7, 5, 3, 1, 6, 4, 2}, new int[]{10, 10, 10, 9, 9, 9, 7})); // 7350
        System.out.println(cashier.getBill(new int[]{2, 3, 5}, new int[]{5, 3, 2})); // 2500

    }
}

@@ -910,17 +910,17 @@
 count %25 
-3
+n
  == 0) %7B
@@ -952,31 +952,23 @@
 e = 
-(
 price
-s.get(product%5Bi%5D)
+ - ((price
  * d
@@ -981,16 +981,17 @@
 t) / 100
+)
 ;%0A      
@@ -1086,16 +1086,16 @@
  total;%0A
+
         
@@ -1105,872 +1105,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Cashier cashier = new Cashier(%0A            3, 50, new int%5B%5D%7B1, 2, 3, 4, 5, 6, 7%7D, new int%5B%5D%7B100, 200, 300, 400, 300, 200, 100%7D);%0A        System.out.println(cashier.getBill(new int%5B%5D%7B1, 2%7D, new int%5B%5D%7B1, 2%7D)); // 500%0A        System.out.println(cashier.getBill(new int%5B%5D%7B3, 7%7D, new int%5B%5D%7B10, 10%7D)); // 4000%0A        System.out.println(cashier.getBill(new int%5B%5D%7B1, 2, 3, 4, 5, 6, 7%7D, new int%5B%5D%7B1, 1, 1, 1, 1, 1, 1%7D)); // 800%0A        System.out.println(cashier.getBill(new int%5B%5D%7B4%7D, new int%5B%5D%7B10%7D)); // 4000%0A        System.out.println(cashier.getBill(new int%5B%5D%7B7, 3%7D, new int%5B%5D%7B10, 10%7D)); // 4000%0A        System.out.println(cashier.getBill(new int%5B%5D%7B7, 5, 3, 1, 6, 4, 2%7D, new int%5B%5D%7B10, 10, 10, 9, 9, 9, 7%7D)); // 7350%0A        System.out.println(cashier.getBill(new int%5B%5D%7B2, 3, 5%7D, new int%5B%5D%7B5, 3, 2%7D)); // 2500%0A%0A    %7D
 %0A%7D%0A

Solve problem 1357