#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void unique_Subsequences(string str, int indx, string newstring , unordered_set<string> st){
if(indx == str.size()){
if(st.count(newstring)){
return;
}
else{
st.insert(newstring);
cout<<newstring<<endl;
return;
}
}
for(auto i : st) cout<<i<<endl;
unique_Subsequences(str, indx+1,newstring+str[indx],st);
unique_Subsequences(str, indx+1, newstring,st);
}
int main()
{
cout<<"Enter the string :";
string str;
cin>>str;
unordered_set<string> st;
unique_Subsequences(str,0,"",st);
return 0;
}
Asked
Active
Viewed 50 times
-2

πάντα ῥεῖ
- 1
- 13
- 116
- 190

Shiva12181
- 1
- 1
-
1[What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Jason Oct 01 '22 at 13:04
-
Please fix the formatting of your code. – Pete Becker Oct 01 '22 at 13:10
-
`cin>>str;` -- Please initialize `str` with the data you are using. There is no need for `cin` here. Just `str = "The data that is giving the issue";` – PaulMcKenzie Oct 01 '22 at 13:29
-
See [Why should I not #include
?](https://stackoverflow.com/q/31816095) and [Why using namespace std is bad practice](https://stackoverflow.com/questions/1452721). – prapin Oct 01 '22 at 17:53
1 Answers
0
you have to pass reference to the set, not a copy, so change this
void unique_Subsequences(..., unordered_set<string> st)
to this:
void unique_Subsequences(..., unordered_set<string>& st)

kubs
- 16
- 1