Sudo Placement | Special Subsequences | C ++ Program to find all special subsequences of the given type ; Function to generate the required subsequences ; If the index pointer has reached the end of input string ; Skip empty ( " ▁ " ) subsequence ; Exclude current character in output string ; Include current character in output string ; Remove the current included character and and include it in its uppercase form ; Function to print the required subsequences ; Output String to store every subsequence ; Set of strings that will store all special subsequences in lexicographical sorted order ; Sort the strings to print in sorted order ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void generateSubsequences ( string input , string output , int idx , vector < string > & ans ) { if ( input [ idx ] == ' \0' ) { if ( output . size ( ) ) ans . push_back ( output ) ; return ; } generateSubsequences ( input , output , idx + 1 , ans ) ; output += input [ idx ] ; generateSubsequences ( input , output , idx + 1 , ans ) ; output . pop_back ( ) ; char upper = input [ idx ] ; upper = toupper ( upper ) ; output += upper ; generateSubsequences ( input , output , idx + 1 , ans ) ; } void printSubsequences ( string S ) { string output ; vector < string > ans ; generateSubsequences ( S , output , 0 , ans ) ; sort ( ans . begin ( ) , ans . end ( ) ) ; for ( auto str : ans ) cout << str << " ▁ " ; } int main ( ) { string S = " ab " ; printSubsequences ( S ) ; return 0 ; }