Skip to content

Instantly share code, notes, and snippets.

@Biazus
Last active February 14, 2023 17:11
Show Gist options
  • Select an option

  • Save Biazus/c54d2ddc37f3fd9b4e7c to your computer and use it in GitHub Desktop.

Select an option

Save Biazus/c54d2ddc37f3fd9b4e7c to your computer and use it in GitHub Desktop.
Desafios: Let Me Count The Ways
#include<cstdio>
#include<iostream>
//Fácil - Let Me Count The Ways
using namespace std;
int main() {
long ways[30001] = {0}; //se nao colocar double da valor negativo
int UScoins[] = {1, 5, 10, 25, 50};
ways[0] = 1;
int n=0, j=0, i=0; //n numero lido
for(i = 0; i < 5; i++){
for(j = UScoins[i]; j <= 30000; j++){
ways[j] += ways[j - UScoins[i]];
}
}
while(cin >> n){
if(ways[n] == 1)
cout << "There is only " << ways[n] << " way to produce " << n << " cents change." << endl;
else
cout << "There are " << ways[n] << " ways to produce " << n << " cents change." << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment