Advertisement
Sajib_Ahmed

greedy alg

May 22nd, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int a[5],i,l,f=0,p,coin,b[5];
  7.     for(i=0;i<5;i++)
  8.     {
  9.         scanf("%d",&a[i]);
  10.     }
  11.  
  12.  int n=sizeof(a)/sizeof(a[0]);
  13.  sort(a,a+n,greater<int>());
  14.  
  15.     for(i=0;i<5;i++)
  16.     {
  17.         cout<<a[i]<<" ";
  18.     }
  19.     printf("\n");
  20.     scanf("%d",&coin);
  21.  
  22.     for(i=0;i<5;i++)
  23.     {
  24.         while(coin>=a[i])
  25.  
  26.         {
  27.             coin=coin-a[i];
  28.             printf("%d ",a[i]);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement