Count of adjacent Vowel Consonant Pairs | C # implementation of the approach ; Function to count the adjacent pairs of consonant and vowels in the String ; Using a set to store the vowels so that checking each character becomes easier ; Variable to store number of consonant - vowel pairs ; If the ith character is not found in the set , means it is a consonant And if the ( i + 1 ) th character is found in the set , means it is a vowel We increment the count of such pairs ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countPairs ( String s ) { HashSet < char > st = new HashSet < char > ( ) ; st . Add ( ' a ' ) ; st . Add ( ' e ' ) ; st . Add ( ' i ' ) ; st . Add ( ' o ' ) ; st . Add ( ' u ' ) ; int count = 0 ; int n = s . Length ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( st . Contains ( s [ i ] ) && ! st . Contains ( s [ i + 1 ] ) ) count ++ ; } return count ; } public static void Main ( String [ ] args ) { String s = " geeksforgeeks " ; Console . Write ( countPairs ( s ) ) ; } }