-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerSet16.4.cpp
More file actions
57 lines (51 loc) · 763 Bytes
/
Copy pathpowerSet16.4.cpp
File metadata and controls
57 lines (51 loc) · 763 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
53
54
55
56
57
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string getindex(int n,int s){
string str="";
int n1=n;
//cout<<"im ghere\n";
while(n>=1){
if(n%2==0){
str="0"+str;
}
else{
str="1"+str;
}
n=n/2;
}
while(str.length()<s){
str="0"+str;
}
//cout<<" Decinal to binary for "<<n1<<" is "<<str<<endl;
return str;
}
void dojob(vector<char>v){
int s=v.size();
cout<<"[";
for(int x=0;x<(2<<(s-1));x++){
string s1=getindex(x,s);
cout<<"(";
for(int j=0;j<s;j++){
if(s1.substr(j,1)=="1"){
cout<<v[j]<<",";
}
}
cout<<"), ";
}
cout<<"]\n";
}
int main(){
int n;
cin>>n;
vector<char>v;
while(n--){
char c,dl;
cin>>c;
v.push_back(c);
}
dojob(v);
return 0;
}