-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoin_sum.cpp
More file actions
52 lines (50 loc) · 897 Bytes
/
coin_sum.cpp
File metadata and controls
52 lines (50 loc) · 897 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
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
int coins[10],in;
map<int,int> tab;
void give(int i,int amount,queue<int> a,bool insert)
{
if(amount<0||i>=in)
return;
else if(insert==true)
{
a.push(coins[i]);
}
if(amount==0)
{
while(!a.empty())
{
cout<<a.front()<<", ";
a.pop();
}
cout<<endl;
}
else
{
give(i,amount-coins[i],a,true);
give(i+1,amount,a,false);
}
}
int main()
{
int n;
cout<<"Enter no. of elements: ";
cin>>n;
cout<<"Enter the elements: ";
int t;in=0;
for(int i=0;i<n;i++)
{
cin>>t;
if(tab.end()==tab.find(t))
{
tab[t]=1;
coins[in++]=t;
}
}
queue<int> a;
int amount;
cout<<"Enter the amount: ";
cin>>amount;
bool insert=false;
give(0,amount,a,insert);
}