Skip to content

Commit a24e2bc

Browse files
committed
added program of subsequences of string
1 parent e53da69 commit a24e2bc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
//Print All Subsequences Of String
6+
void printAllSubsequences(string &input, int i, string t){
7+
// i to keep track of string indexes
8+
if(i == input.length()){
9+
cout<<t<<endl;
10+
return;
11+
}
12+
13+
//For element select it in out subsequence once and leave it out once
14+
printAllSubsequences(input, i+1, t+input[i]);
15+
printAllSubsequences(input, i+1, t);
16+
17+
}
18+
19+
20+
21+
int main(){
22+
string input;
23+
cout<<"Enter the string of which you want to find subsequences"<<endl;
24+
cin >> input;
25+
26+
cout<<"Subsequences of string are: "<<endl;
27+
printAllSubsequences(input, 0, "");
28+
29+
}
30+
31+

0 commit comments

Comments
 (0)