Skip to content

Commit 28ed88b

Browse files
committed
subsequences
1 parent 5b15ea4 commit 28ed88b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Subsequences/question.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Print all the subsequences of a string. A String is a subsequence of a given String,
2+
that is generated by deleting some character of a given string without changing
3+
its order.
4+
Example:
5+
Input : abc
6+
Output : a, b, c, ab, bc, ac, abc

Subsequences/subsequences.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//find all the sub sequences of a string
2+
#include <iostream>
3+
using namespace std;
4+
char output[100] = "";
5+
6+
void printSubSeq(char str[], int be, int idx)
7+
{
8+
if (str[be] == '\0')
9+
{
10+
output[idx] = '\0';
11+
cout << output << endl;
12+
return;
13+
}
14+
15+
printSubSeq(str, be + 1, idx);
16+
output[idx] = str[be];
17+
printSubSeq(str, be + 1, idx + 1);
18+
}
19+
20+
21+
int main() {
22+
char str[100];
23+
cin >> str;
24+
25+
26+
printSubSeq(str, 0, 0);
27+
}

0 commit comments

Comments
 (0)