I'm trying to build an exchange algorithm to exchange coins in the same number as they are in stock. I have a dictionary containing key-value pairs of denomination & amounts
The input is the value to return for example €2,80
I need an algorithm to calculate the best way to return the money taking the stock into account.
(The best way is the way where the numbers of coins left in stock have the lowest standard deviation, this means the stock for all denominations is the same)
So in this example I need to return coins of €1, 20ct & 10ct because €2 and 50ct coins are almost out of stock.
The best output in this case is:
{200, 0},
{100, 2},
{50, 0},
{20, 3},
{10, 2}
How can i calculate the best numbers to return per denomination using a c++ algorithm and keep the stock the same for all coins?
#include <map>
static map<int, int, greater<int>> ValueAmount = {
{200, 3},
{100, 20},
{50, 2},
{20, 15},
{10, 14}
};
std::map<int, int> PayoutAlgorithm(std::map<int, int> ValueAmount, long amountToPay){
}
int main(int argc, char** argv){
...
bool succes = ReturnMoney(PayoutAlgorithm());
...
return 1;
}
where map ValueAmount is a key-value pair. Key is denomination of coin, value is amount of coins present.