forked from matthewsamuel95/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mincoins.cpp
37 lines (32 loc) · 780 Bytes
/
mincoins.cpp
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
#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]);
// Driver program
void findMin(int V)
{
// Initialize result
vector<int> ans;
// Traverse through all denomination
for (int i=n-1; i>=0; i--)
{
// Find denominations
while (V >= deno[i])
{
V -= deno[i];
ans.push_back(deno[i]);
}
}
// Print result
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " ";
}
// Driver program
int main()
{
int n;
cin>>n;
cout << "Following is minimal number of change for " << n << " is ";
findMin(n);
return 0;