-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin_changing.cpp
50 lines (43 loc) · 977 Bytes
/
coin_changing.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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main()
{
int total, N;
cout << "Number of Taka available: " << endl;
cin >> N;
vector<int> coin(N);
cout << "Input All Values of Taka: " << endl;
for (int i = 0; i < N; i++)
{
int p;
cin >> p;
coin.push_back(p);
}
cout << "Enter total payment: " << endl;
cin >> total;
sort(coin.begin(), coin.end());
reverse(coin.begin(), coin.end());
int c, num[N], i = 0;
while (total > 0 && i < N)
{
num[i] = 0;
if (coin[i] <= total)
{
c = coin[i];
num[i] = total / c;
total -= (num[i] * c);
}
i++;
}
while (i < N)
{
num[i] = 0;
i++;
}
cout << endl;
for (i = 0; i < N; i++)
{
cout << num[i] << " Note(s) of " << coin[i] << " Taka" << endl;
}
return 0;
}