text: Encrypt string with product of number of vowels and consonants in substring of size k | C # Program to Encrypt String with product of number of vowels and consonants in subString of size k ; isVowel ( ) is a function that returns true for a vowel and false otherwise . ; function to Encrypt the String ; cv to count vowel cc to count consonants ; Counting prefix count of vowel and prefix count of consonants ; generating the encrypted String . ; Driver Code
code: using System ; class GFG { static bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static String encryptString ( char [ ] s , int n , int k ) { int [ ] cv = new int [ n ] ; int [ ] cc = new int [ n ] ; if ( isVowel ( s [ 0 ] ) ) cv [ 0 ] = 1 ; else cc [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { cv [ i ] = cv [ i - 1 ] + ( isVowel ( s [ i ] ) == true ? 1 : 0 ) ; cc [ i ] = cc [ i - 1 ] + ( isVowel ( s [ i ] ) == true ? 0 : 1 ) ; } String ans = " " ; int prod = 0 ; prod = cc [ k - 1 ] * cv [ k - 1 ] ; ans += String . Join ( " " , prod ) ; for ( int i = k ; i < s . Length ; i ++ ) { prod = ( cc [ i ] - cc [ i - k ] ) * ( cv [ i ] - cv [ i - k ] ) ; ans += String . Join ( " " , prod ) ; } return ans ; } public static void Main ( String [ ] args ) { String s = " hello " ; int n = s . Length ; int k = 2 ; Console . Write ( encryptString ( s . ToCharArray ( ) , n , k ) + " STRNEWLINE " ) ; } }