Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define CantDen 6 //Cantidad de Denominaciones
- short monedas[CantDen] = { 1,5,10,20,25,50 };
- struct sencillo {
- short cant = 0;
- short moneda = 0;
- sencillo(short cant = SHRT_MAX, int moneda = 0) : cant(cant), moneda(moneda) {};
- };
- sencillo valores[100];
- inline void minimoSencillo(int valor) {
- for (short i = 0; valor >= monedas[CantDen] && i < 6; i++) {
- short moneda = monedas[i];
- short cantidad = 1 + valores[valor - moneda].cant;
- if (valores[valor].cant > cantidad) {
- valores[valor].cant = cantidad;
- valores[valor].moneda = moneda;
- }
- }
- }
- int main() {
- valores[0].cant = 0;
- short valor;
- for (valor = 1; valor < 100; valor++)
- minimoSencillo(valor);
- cout << "Ingrese el valor a sencillar: "; cin >> valor;
- cout << "La cantidad de monedas para ese valor es: " << valores[valor].cant << endl;
- cout << "Las monedas son: ";
- while (valor > 0) {
- cout << valores[valor].moneda << ",";
- valor -= valores[valor].moneda;
- }
- cout << "\b." << endl;
- system("pause>0");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement