Remove consecutive vowels from string

02 Jun, 2022
Given a string s of lowercase letters, we need to remove consecutive vowels from the stringNote : Sentence should not contain two consecutive vowels ( a, e, i, o, u).Examples :  
Input: geeks for geeks
Output: geks for geks

Input : your article is in queue 
Output : your article is in qu
 
Approach: Iterate string using a loop and check for the repetitiveness of vowels in a given sentence and in case if consecutive vowels are found then delete the vowel till coming next consonant and printing the updated string.  
C++
Java
Python3
C#
PHP
Javascript
// C++ program for printing sentence// without repetitive vowels#include <bits/stdc++.h>using namespace std; // function which returns True or False// for occurrence of a vowelbool is_vow(char c){    // this compares vowel with    // character 'c'    return (c == 'a') || (c == 'e') ||           (c == 'i') || (c == 'o') ||           (c == 'u');} // function to print resultant stringvoid removeVowels(string str){    // print 1st character    printf("%c", str[0]);     // loop to check for each character    for (int i = 1; str[i]; i++)         // comparison of consecutive characters        if ((!is_vow(str[i - 1])) ||            (!is_vow(str[i])))            printf("%c", str[i]);} // Driver Codeint main(){    char str[] = " geeks for geeks";    removeVowels(str);} // This code is contributed by Abhinav96
// Java program for printing sentence// without repetitive vowelsimport java.io.*;import java.util.*;import java.lang.*; class GFG{    // function which returns    // True or False for    // occurrence of a vowel    static boolean is_vow(char c)    {        // this compares vowel        // with character 'c'        return (c == 'a') || (c == 'e') ||               (c == 'i') || (c == 'o') ||               (c == 'u');    }         // function to print    // resultant string    static void removeVowels(String str)    {        // print 1st character        System.out.print(str.charAt(0));             // loop to check for        // each character        for (int i = 1;                 i < str.length(); i++)                 // comparison of            // consecutive characters            if ((!is_vow(str.charAt(i - 1))) ||                (!is_vow(str.charAt(i))))                System.out.print(str.charAt(i));    }         // Driver Code    public static void main(String[] args)    {        String str = "geeks for geeks";        removeVowels(str);    }}
# Python3 implementation for printing# sentence without repetitive vowels # function which returns True or False# for occurrence of a voweldef is_vow(c):     # this compares vowel with    # character 'c'    return ((c == 'a') or (c == 'e') or            (c == 'i') or (c == 'o') or            (c == 'u')); # function to print resultant stringdef removeVowels(str):     # print 1st character    print(str[0], end = "");     # loop to check for each character    for i in range(1,len(str)):         # comparison of consecutive        # characters        if ((is_vow(str[i - 1]) != True) or            (is_vow(str[i]) != True)):                         print(str[i], end = ""); # Driver codestr= " geeks for geeks";removeVowels(str); # This code is contributed by mits
// C# program for printing sentence// without repetitive vowelsusing System; class GFG{    // function which returns    // True or False for    // occurrence of a vowel    static bool is_vow(char c)    {        // this compares vowel        // with character 'c'        return (c == 'a') || (c == 'e') ||               (c == 'i') || (c == 'o') ||               (c == 'u');    }         // function to print    // resultant string    static void removeVowels(string str)    {        // print 1st character        Console.Write(str[0]);             // loop to check for        // each character        for (int i = 1; i < str.Length; i++)                 // comparison of            // consecutive characters            if ((!is_vow(str[i - 1])) ||                (!is_vow(str[i])))                Console.Write(str[i]);    }         // Driver Code    static void Main()    {        string str = "geeks for geeks";        removeVowels(str);    }} // This code is contributed// by Manish Shaw(manishshaw1)
<?php// PHP implementation for printing// sentence without repetitive vowels // function which returns True or False// for occurrence of a vowelfunction is_vow($c){    // this compares vowel with    // character 'c'    return ($c == 'a') || ($c == 'e') ||           ($c == 'i') || ($c == 'o') ||           ($c == 'u');} // function to print resultant stringfunction removeVowels($str){    // print 1st character    printf($str[0]);     // loop to check for each character    for ($i = 1; $i < strlen($str); $i++)         // comparison of consecutive        // characters        if ((!is_vow($str[$i - 1])) ||            (!is_vow($str[$i])))                         printf($str[$i]);} // Driver code$str= " geeks for geeks";removeVowels($str); // This code is contributed by mits?>
<script> // JavaScript program for printing sentence// without repetitive vowels // function which returns True or False// for occurrence of a vowelfunction is_vow(c){     // this compares vowel with    // character 'c'    return (c == 'a') || (c == 'e') ||        (c == 'i') || (c == 'o') ||        (c == 'u');} // function to print resultant stringfunction removeVowels(str){    // print 1st character    document.write(str[0]);     // loop to check for each character    for (let i = 1; i<str.length; i++)         // comparison of consecutive characters        if ((!is_vow(str[i - 1])) ||            (!is_vow(str[i])))            document.write(str[i]);} // Driver Codelet str = " geeks for geeks";removeVowels(str); // This code is contributed by shinjanpatra </script>
geks for geks
 
Time Complexity: O(n), where n is the length of the string
Space Complexity: O(n), where n is the length of the string
Remove consecutive vowels from string | GeeksforGeeks - YouTubeGeeksforGeeks529K subscribersRemove consecutive vowels from string | GeeksforGeeksWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.More videosMore videosYou're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 2:04•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=Q_hsm2Qh9SE" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>
Mithun Kumar
manishshaw1
sumitgumber28
shinjanpatra
rohitmishra051000
vowel-consonant
School Programming
Strings
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Introduction To PYTHON
Interfaces in Java
Operator Overloading in C++
Polymorphism in C++
Types of Operating Systems
Write a program to reverse an array or string
Write a program to print all permutations of a given string
Different Methods to Reverse a String in C++
Check for Balanced Brackets in an expression (well-formedness) using Stack
Longest Common Subsequence | DP-4