Last active
February 14, 2023 17:11
-
-
Save Biazus/c54d2ddc37f3fd9b4e7c to your computer and use it in GitHub Desktop.
Desafios: Let Me Count The Ways
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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