Print all Subsequences of String which Start with Vowel and End with Consonant . | C ++ program to generate all the subse - quence starting with vowel and ending with consonant . ; Set to store all the subsequences ; Utility method to check vowel ; Utility method to check consonant ; It computes all the possible substring that starts with vowel and end with consonent ; iterate over the entire string ; test ith character for vowel ; if the ith character is vowel iterate from end of the string and check for consonant . ; test jth character for consonant . ; once we get a consonant add it to the hashset ; drop each character of the substring and recur to generate all subsequence of the substring ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; set < string > st ; bool isVowel ( char c ) { return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) ; } bool isConsonant ( char c ) { return ! isVowel ( c ) ; } void subsequence ( string str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( isVowel ( str [ i ] ) ) { for ( int j = str . length ( ) - 1 ; j >= i ; j -- ) { if ( isConsonant ( str [ j ] ) ) { string str_sub = str . substr ( i , j + 1 ) ; st . insert ( str_sub ) ; for ( int k = 1 ; k < str_sub . length ( ) - 1 ; k ++ ) { string sb = str_sub ; sb . erase ( sb . begin ( ) + k ) ; subsequence ( sb ) ; } } } } } } int main ( ) { string s = " xabcef " ; subsequence ( s ) ; for ( auto i : st ) cout << i << " ▁ " ; cout << endl ; return 0 ; }