Count of adjacent Vowel Consonant Pairs | C ++ Program to implement the above 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countPairs ( string s ) { set < char > st ; st . insert ( ' a ' ) ; st . insert ( ' e ' ) ; st . insert ( ' i ' ) ; st . insert ( ' o ' ) ; st . insert ( ' u ' ) ; int count = 0 ; int n = s . size ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( st . find ( s [ i ] ) == st . end ( ) && st . find ( s [ i + 1 ] ) != st . end ( ) ) count ++ ; } return count ; } int main ( ) { string s = " geeksforgeeks " ; cout << countPairs ( s ) ; return 0 ; }