forked from AmaanKhan63/Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowset.cpp
50 lines (46 loc) · 1004 Bytes
/
powset.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 ;
void solve(string ip, string op)
{
if(ip.length() == 0)
{
cout << op << " " ;
return ;
}
string op1 = op ;
string op2 = op ;
op2.push_back(ip[0]) ;
ip.erase(ip.begin()+0) ;
solve(ip,op1) ;
solve(ip,op2) ;
return ;
}
int main()
{
string ip = "abcdefgh" , op="";
solve(ip,op) ;
}
------------------------------------------------------
void solve(string ip, string op,vector<string>& ans)
{
if(ip.length()==0 && op.length()!=0)
{
ans.push_back(op) ;
return ;
}
string op1 = op ;
string op2 = op ;
op2.push_back(ip[0]) ;
ip.erase(ip.begin()+0) ;
solve(ip,op1,ans) ;
solve(ip,op2,ans) ;
return ;
}
vector<string> AllPossibleStrings(string s){
// Code here
string ip = s , op = "" ;
vector<string> ans ;
solve(ip,op,ans) ;
sort(ans.begin(),ans.end()) ;
return ans ;
}