Advertisement
saykotislam

Untitled

Jul 27th, 2021
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int a[100];
  5. int conchange(int coin[],int tc, int v)
  6. {
  7.     int i, cn = 0;
  8.     for(i = 0; i < tc; i++)
  9.     {
  10.         while(v>=coin[i])
  11.         {
  12.             v=v-coin[i];
  13.             a[cn] = coin[i];
  14.             cn++;
  15.         }
  16.         if(v == 0)
  17.             break;
  18.     }
  19.     return cn;
  20. }
  21.  
  22. void sort(int coin[], int tc)
  23. {
  24.     int key;
  25.     int j=0,n;
  26.     for(int i=1;i<tc;i++){
  27.         key=coin[i];
  28.         j=i-1;
  29.         while(j>=0 && coin[j]<key){
  30.             coin[j+1]=coin[j];
  31.             j=j-1;
  32.         }
  33.         coin[j+1]=key;
  34.     }
  35. }
  36.  
  37. int main()
  38. {
  39.     cout<<"Enter Test Case: "<<endl;
  40.     int t;
  41.     cin>>t;
  42.  
  43.     for(int j=0;j<t;j++){
  44.     cout<<"Case: "<<j+1<<endl;
  45.     int tc;
  46.     cout<<"Total Currency you have: ";
  47.     cin>>tc;
  48.     int coin[tc];
  49.     cout<<"Currency you have: ";
  50.     for(int i=0;i<tc;i++){
  51.         cin>>coin[i];
  52.     }
  53.     sort(coin,tc);
  54.     int n=tc;
  55.     cout<<"Your Friends amount: ";
  56.     int v;
  57.     cin>>v;
  58.     int c = conchange(coin,tc,v);
  59.     cout<<"Amount of coins: "<<c<<endl;
  60.     cout<<"All coins: ";
  61.     for(int i = 0; i < c; i++){
  62.         cout<<a[i]<<" ";
  63.     }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement