leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1357.cpp (694B)


      1 class Cashier {
      2     uint16_t price[201];
      3     uint16_t n, crnt = 0;
      4     double discount;
      5 
      6   public:
      7     Cashier(int n, int discount, const vector<int> &products, const vector<int> &prices)
      8         : n(n), discount((double)(100 - discount) / 100.0) {
      9         for (int i = 0; i < products.size(); i++)
     10             this->price[products[i]] = prices[i];
     11     }
     12 
     13     double getBill(const vector<int> &product, const vector<int> &amount) {
     14         uint32_t total = 0;
     15         for (uint8_t i = 0; i < product.size(); i++)
     16             total += price[product[i]] * amount[i];
     17 
     18         if (++crnt == n) {
     19             crnt = 0;
     20             return total * discount;
     21         }
     22 
     23         return total;
     24     }
     25 };