fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std ;
  4. long long n,i,s[30001],j;
  5. long long c[] = { 1 , 5 , 10 , 25 , 50 } ;
  6. int main()
  7. {
  8. s[0] = 1 ;
  9. for ( i = 0 ; i < 5 ; i++ )
  10. {
  11. for ( j = c[i] ; j <= 30000 ; j++ )
  12. {
  13. s[j] += s[j-c[i]] ;
  14. }
  15. }
  16. while(cin >> n )
  17. {
  18. if ( s[n] == 1 ) {
  19. cout << "There is only " << s[n] << " way to produce " << n << " cents change." << endl ;
  20. }
  21. else cout << "There are " << s[n] << " ways to produce " << n << " cents change." << endl ;
  22. }
  23.  
  24.  
  25. }
  26.  
Success #stdin #stdout 0s 4396KB
stdin
0 1 2 3 4 5 6 7 8 9 10 
stdout
There is only 1 way to produce 0 cents change.
There is only 1 way to produce 1 cents change.
There is only 1 way to produce 2 cents change.
There is only 1 way to produce 3 cents change.
There is only 1 way to produce 4 cents change.
There are 2 ways to produce 5 cents change.
There are 2 ways to produce 6 cents change.
There are 2 ways to produce 7 cents change.
There are 2 ways to produce 8 cents change.
There are 2 ways to produce 9 cents change.
There are 4 ways to produce 10 cents change.