Print all Subsequences of String which Start with Vowel and End with Consonant . | C # Program to generate all the subsequence starting with vowel and ending with consonant . ; Set to store all the subsequences ; 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 ; Utility method to check vowel ; Utility method to check consonant ; Driver code
using System ; using System . Collections . Generic ; using System . Text ; class Subsequence { static HashSet < String > st = new HashSet < String > ( ) ; static 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 . Substring ( i , j - i + 1 ) ; st . Add ( str_sub ) ; for ( int k = 1 ; k < str_sub . Length - 1 ; k ++ ) { StringBuilder sb = new StringBuilder ( str_sub ) ; sb . Remove ( k , 1 ) ; subsequence ( sb . ToString ( ) ) ; } } } } } } static bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static bool isConsonant ( char c ) { return ! isVowel ( c ) ; } public static void Main ( String [ ] args ) { String s = " xabcef " ; subsequence ( s ) ; foreach ( String str in st ) Console . Write ( str + " , ▁ " ) ; } }