Advertisement
apl-mhd

coinChangeNew

Oct 6th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     int coin[9] = {1, 2, 5,10, 20, 50, 100, 500, 1000};
  11.  
  12.     int tk, sum=0, i = 8;
  13.  
  14.     cin>>tk;
  15.  
  16.     while( i != -1){
  17.  
  18.         if(coin[i] <=tk){
  19.  
  20.             sum = sum + coin[i];
  21.             printf("%d + ", coin[i]);
  22.             tk = tk - coin[i];
  23.  
  24.  
  25.         }
  26.  
  27.         else
  28.  
  29.             i--;
  30.  
  31.     }
  32.  
  33.     printf("= %d\n", sum);
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement