Unable to pass two cases.please tell where i am wrong and also my approach to match desired output format.
My code
Subsequences Problem
hi @Prankur-Tewari-2574939259288733
i have seen your last submission on this problem
Submission #5478381
#include
using namespace std;
int cnt=0;
void subsequence(char *in ,char *out,int i ,int j){
if(in[i]==’\0’){
out[j]=’\0’;
cout<<out<<" ";
cnt++;
return;
}
out[j]=in[i];
subsequence(in,out,i+1,j+1);
subsequence(in,out,i+1,j);
you have to change the order of calling recursive function
first call without including the character and then call with including the character in your out
subsequence(in,out,i+1,j);
out[j]=in[i];
subsequence(in,out,i+1,j+1);
}
int main() {
char in[100];
char out[100];
cin>>in;
cout<<in;
subsequence(in,out,0,0);
cout<<"\n"<<cnt;
return 0;
}
No sir its still not working
sir by changing the order we wont get the desired output format
Take as input str, a string. We are concerned with all the possible subsequences of str. E.g.
a. Write a recursive function which returns the count of subsequences for a given string. Print the value returned.
b. Write a recursive function which prints all possible subsequences for a “abcd” has following subsequences “”, “d”, “c”, “cd”, “b”, “bd”, “bc”, “bcd”, “a”, “ad”, “ac”, “acd”, “ab”, “abd”, “abc”, “abcd”.given string (void is the return type for function).
Note: Use cin for input for C++
Input Format
Enter a string
Constraints
None
Output Format
Display the total no. of subsequences and also print all the subsequences in a space separated manner
Sample Input
abcd
Sample Output
d c cd b bd bc bcd a ad ac acd ab abd abc abcd
16
out[j]=in[i];
subsequence(in,out,i+1,j+1);
subsequence(in,out,i+1,j);
you have not change the order correctly
right way is
subsequence(in,out,i+1,j);
out[j]=in[i];
subsequence(in,out,i+1,j+1);
as i told you before