Skip to content

Commit 38e6074

Browse files
Merge pull request #113 from Rupali409/main
Create Minimum number of Coins .cpp
2 parents 4c371b9 + da6a534 commit 38e6074

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Minimum number of Coins .cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Initial Template for C++
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
// } Driver Code Ends
7+
// User function Template for C++
8+
9+
class Solution{
10+
public:
11+
vector<int> minPartition(int x)
12+
{
13+
vector<int>st;
14+
int a[]={1,2,5,10,20,50,100,200,500,2000};
15+
int n=10;
16+
17+
sort(a,a+n,greater<int>());
18+
int ans=0;
19+
for(int i=0;i<n;i++){
20+
// int res=x/a[i];
21+
// if(res>0 ){
22+
// ans=ans+res;
23+
// x=x%a[i];
24+
// st.push_back(a[i]);
25+
// }
26+
while (x >= a[i]) {
27+
x -= a[i];
28+
st.push_back(a[i]);
29+
}
30+
31+
}
32+
33+
34+
return st;
35+
}
36+
};
37+
38+
// { Driver Code Starts.
39+
40+
int main(){
41+
int t;
42+
cin>>t;
43+
while(t--){
44+
int N;
45+
cin>>N;
46+
47+
Solution ob;
48+
vector<int> numbers = ob.minPartition(N);
49+
for(auto u: numbers)
50+
cout<<u<<" ";
51+
cout<<"\n";
52+
}
53+
return 0;
54+
} // } Driver Code Ends

0 commit comments

Comments
 (0)