forked from AllAlgorithms/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimumCoins.cpp
More file actions
41 lines (35 loc) · 878 Bytes
/
Copy pathminimumCoins.cpp
File metadata and controls
41 lines (35 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Given a value V and the list of available denomination of money,
// find minimum number of coins and/or notes needed to make the change.
#include <bits/stdc++.h>
using namespace std;
// All denominations of Indian Currency
int deno[] = { 1, 2, 5, 10, 20,
50, 100, 500, 1000 };
int n = sizeof(deno) / sizeof(deno[0]);
vector<int> calculate(int V)
{
sort(deno, deno + n);
vector<int> ans;
for (int i = n - 1; i >= 0; i--) {
while (V >= deno[i]) {
V -= deno[i];
ans.push_back(deno[i]);
}
}
return ans;
//for (int i = 0; i < ans.size(); i++)
//cout << ans[i] << " ";
}
int main()
{
int n;
cout<<"Enter the monitory value: ";
cin>>n;
cout << "Following is minimal number of change for " << n
<< ": ";
vector<int> ans = calculate(n);
for(auto i: ans)
cout<<i<<" ";
cout<<"\nMinimum Denominations required: "<<ans.size();
return 0;
}