forked from vishal8113/Hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerSet.cpp
74 lines (64 loc) · 818 Bytes
/
PowerSet.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//This is a C++ code..
// This code is for finding power set of strings which is passed to function..
//I have also shown some sample Outputs at the end
#include <iostream>
#include <cmath>
using namespace std;
void printPowerSet(string s){
int x=s.length();
int total=pow(2,x)-1;
for(int i=0;i<=total;i++){
int tempi=i;
for(int j=0;j<x;j++){
if((tempi&1)){
cout<<s[j];
}
tempi=tempi>>1;
}
cout<<endl;
}
}
int main() {
// string s = "abc";
string s;
cin>>s;
printPowerSet(s);
}
//This code is contributed by Rajat Dhull
//Sample test case
/*
//Input
Rajat
//Output
R
a
Ra
j
Rj
aj
Raj
a
Ra
aa
Raa
ja
Rja
aja
Raja
t
Rt
at
Rat
jt
Rjt
ajt
Rajt
at
Rat
aat
Raat
jat
Rjat
ajat
Rajat
*/