Advertisement
kiwser

greedy

Jul 2nd, 2021
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4. int main(){
  5.     int coin[10] = {20,5,2,1};
  6.     int count_coin[4]={0};
  7.  
  8.     int value;
  9.     ///117
  10.     scanf("%d", &value);
  11.  
  12.     for(int i = 0; i < 4; i++){
  13.         count_coin[i] = value/coin[i];
  14.         value = value-count_coin[i]*coin[i];
  15.  
  16.         if(!value)break;
  17.     }
  18.  
  19.     printf("Coin = CoinCount\n");
  20.     for(int i = 0; i < 4; i++){
  21.         printf("%d = %d\n", coin[i], count_coin[i]);
  22.     }
  23.  
  24.  
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement