1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <cstdio>
#define MAX 200
using namespace std;
bool NextAmountEven(int, int );
char **M_GreedyBox(int [], int);
int main()
{
int coins[] = {200, 100, 50, 20, 10, 5, 2, 1};
int *CoinPtr = coins;
int size = sizeof coins / sizeof *coins;
char **NumToMax = new char *[10];
NumToMax = M_GreedyBox(CoinPtr, size);
for (int A = 0; A < size - 1; ++A)
cout << NumToMax[A] << " ";
cout <<endl;
return 0;
}
char **M_GreedyBox(int *arr, int sz)
{
char **toRet = new char*[10];
int temp;
int temp2;
for (int S = 0; S < sz - 1; ++S)
{
toRet[S] = new char[10];
temp = (arr[S] / arr[S + 1]);
temp2 = arr[S] - temp*(arr[S + 1]);
if (NextAmountEven(arr[S], arr[S + 1]))
sscanf(toRet[S], "%d R 0", &temp);
else
sscanf(toRet[S], "%d R %d", &temp, &temp2);
}
return toRet;
}
bool NextAmountEven (int Set, int Next)
{
if (Set % Next == 0)
return true;
return false;
}
|