Longest Subsequence of a String containing only vowels | C ++ program to find the longest subsequence containing only vowels ; Function to check whether a character is vowel or not ; Returns true if x is vowel ; Function to find the longest subsequence which contain all vowels ; Length of the string ; Iterating through the string ; Checking if the character is a vowel or not ; If it is a vowel , then add it to the final string ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char x ) { x = tolower ( x ) ; return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } string longestVowelSubsequence ( string str ) { string answer = " " ; int n = str . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isVowel ( str [ i ] ) ) { answer += str [ i ] ; } } return answer ; } int main ( ) { string str = " geeksforgeeks " ; cout << longestVowelSubsequence ( str ) << endl ; return 0 ; }