Longest Subsequence of a String containing only Consonants | C ++ program to find the longest subsequence which contain all consonants ; Returns true if x is consonants . ; Function to check whether a character is consonants or not ; Function to find the longest subsequence which contain all consonants ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isConsonants ( char x ) { x = tolower ( x ) ; return ! ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } string longestConsonantsSubsequence ( string str ) { string answer = " " ; int n = str . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isConsonants ( str [ i ] ) ) { answer += str [ i ] ; } } return answer ; } int main ( ) { string str = " geeksforgeeks " ; cout << longestConsonantsSubsequence ( str ) << endl ; return 0 ; }