The question is to find all possible substrings in a given string.
I know this question is somewhat similar to this.
Generate all unique substrings for given string
But i'm trying it on my own. I have generated all possible combinations but problem is i want to eliminate some strings with space in them.
int main()
{
int t;
cin>>t;
while(t>0){
long long int n;
cin>>n;
string S;
cin>>S;
for(int i=1; i<=S.size(); i++) {
for(int j=0; j<=S.size()-1; j++) {
cout<<S.substr(j,i)<<endl;
}
}
t--;
}
return 0;
}
input:
1
3
abb
Actual output:
a
b
b
ab
bb
b
abb
bb
b
Expected output:
a
b
b
ab
bb
abb
As you can see there are some terms with space in them which i want to eliminate like 6th,8th and 9th terms in Actual output.