A company is planning to provide an extra discount to it's customers. Every order has an order ID associated with it which is a sequence of digits. The discount is calculated as the count of unique repeating digits in the order ID. Write a code to find the discount percentile given to the customers.
#include <iostream>
int discount(int order) {
int digits[10] = {0};
while (order > 0) {
int d = order % 10;
digits[d]++;
order = order / 10;
}
int res = 0;
for (int i=0; i<10; i++) {
if (digits[i] > 1) {
res++;
}
}
return res;
}
int main() {
int order;
std::cin >> order;
int p = discount(order);
std::cout << "The discount is " << p << "%";
return 0;
}
Comments
Leave a comment