Skip to content

Commit 580b2a3

Browse files
authored
Merge pull request kothariji#443 from vanshikajha/master
indian coin change problem
2 parents 2f1ed5e + 5ddf9f0 commit 580b2a3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Greedy/indian coin change problem.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
int deno[] = { 1, 2, 5, 10, 20,
6+
50, 100, 500, 1000 };
7+
int n = sizeof(deno) / sizeof(deno[0]);
8+
9+
void findMin(int V)
10+
{
11+
sort(deno, deno + n);
12+
13+
14+
vector<int> ans;
15+
16+
17+
for (int i = n - 1; i >= 0; i--) {
18+
19+
20+
while (V >= deno[i]) {
21+
V -= deno[i];
22+
ans.push_back(deno[i]);
23+
}
24+
}
25+
26+
27+
for (int i = 0; i < ans.size(); i++)
28+
cout << ans[i] << " ";
29+
}
30+
31+
32+
int main()
33+
{
34+
int n = 93;
35+
cout << "Following is minimal"
36+
<< " number of change for " << n
37+
<< ": ";
38+
findMin(n);
39+
return 0;
40+
}

0 commit comments

Comments
 (0)