Count of substrings consisting only of vowels | C ++ program to Count all substrings in a string which contains only vowels ; Function to check if a character is vowel or not ; Function to check whether string contains only vowel ; Check if the character is not vowel then invalid ; Function to Count all substrings in a string which contains only vowels ; Generate all substring of s ; If temp contains only vowels ; Increment the count ; Driver Program
#include <iostream> NEW_LINE using namespace std ; bool isvowel ( char ch ) { return ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) ; } bool isvalid ( string & s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! isvowel ( s [ i ] ) ) return false ; } return true ; } int CountTotal ( string & s ) { int ans = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { string temp = " " ; for ( int j = i ; j < n ; j ++ ) { temp += s [ j ] ; if ( isvalid ( temp ) ) ans += 1 ; } } return ans ; } int main ( ) { string s = " aeoibsddaaeiouudb " ; cout << ( CountTotal ( s ) ) << endl ; return 0 ; }