Program to accept a Strings which contains all the Vowels - GeeksforGeeks

21 May, 2021
Given a string S, the task is to check and accept the given string if it contains all vowels i.e. ‘a’, ‘e’, ‘i’.’o’, ‘u’ or ‘A’, ‘E’, ‘I’, ‘O’, ‘U’.Examples:  
Input: S = “GeeksforGeeks” Output: Not Accepted Since S does not contain vowels a, i and uInput: S = “ABeeIghiObhkUul” Output: Accepted Since S contains all vowels a, e, i, o and u  
 
Approach:  
Hashing can be used to solve this problem easily. For this, a hash data structure needs to be created of size 5 such that the index 0, 1, 2, 3, and 4 represent the vowels a, e, i, o, and u.
Create a Boolean Array, as the hash data structure, to check that all vowels are present or not in the string.
Iterate over the string character by character and if the character is vowel then mark that vowel present in the Boolean Array
After the Iteration of the string, check that is there any vowel which is not present in the boolean array.
Below is the implementation of the above approach: 
C++
Java
Python3
C#
Javascript
// C++ implementation to check that// a string contains all vowels #include <iostream>using namespace std; // Function to to check that// a string contains all vowelsint checkIfAllVowels(string str){     // Hash Array of size 5    // such that the index 0, 1, 2, 3 and 4    // represent the vowels a, e, i, o and u    int hash[5] = { 0 };     // Loop the string to mark the vowels    // which are present    for (int i = 0; i < str.length(); i++) {         if (str[i] == 'A' || str[i] == 'a')            hash[0] = 1;         else if (str[i] == 'E' || str[i] == 'e')            hash[1] = 1;         else if (str[i] == 'I' || str[i] == 'i')            hash[2] = 1;         else if (str[i] == 'O' || str[i] == 'o')            hash[3] = 1;         else if (str[i] == 'U' || str[i] == 'u')            hash[4] = 1;    }     // Loop to check if there is any vowel    // which is not present in the string    for (int i = 0; i < 5; i++) {        if (hash[i] == 0) {            return 1;        }    }    return 0;} // Function to to check that// a string contains all vowelsint checkIfAllVowelsArePresent(string str){     if (checkIfAllVowels(str))        cout << "Not Accepted\n";    else        cout << "Accepted\n";} // Driver Codeint main(){    string str = "aeioubc";    checkIfAllVowelsArePresent(str);     return 0;}
// Java implementation to check that// a String contains all vowels class GFG{ // Function to to check that// a String contains all vowelsstatic int checkIfAllVowels(String str){     // Hash Array of size 5    // such that the index 0, 1, 2, 3 and 4    // represent the vowels a, e, i, o and u    int []hash = new int[5];     // Loop the String to mark the vowels    // which are present    for (int i = 0; i < str.length(); i++)    {         if (str.charAt(i) == 'A' || str.charAt(i) == 'a')            hash[0] = 1;         else if (str.charAt(i) == 'E' || str.charAt(i) == 'e')            hash[1] = 1;         else if (str.charAt(i) == 'I' || str.charAt(i) == 'i')            hash[2] = 1;         else if (str.charAt(i) == 'O' || str.charAt(i) == 'o')            hash[3] = 1;         else if (str.charAt(i) == 'U' || str.charAt(i) == 'u')            hash[4] = 1;    }     // Loop to check if there is any vowel    // which is not present in the String    for (int i = 0; i < 5; i++)    {        if (hash[i] == 0)        {            return 1;        }    }return 0;} // Function to to check that// a String contains all vowelsstatic void checkIfAllVowelsArePresent(String str){     if (checkIfAllVowels(str) == 1)        System.out.print("Not Accepted\n");    else        System.out.print("Accepted\n");} // Driver Codepublic static void main(String[] args){    String str = "aeioubc";    checkIfAllVowelsArePresent(str);}} // This code is contributed by 29AjayKumar
# Python3 implementation to check that# a string contains all vowels # Function to to check that# a string contains all vowelsdef checkIfAllVowels(string) :     # Hash Array of size 5    # such that the index 0, 1, 2, 3 and 4    # represent the vowels a, e, i, o and u    hash = [0]*5 ;         # Loop the string to mark the vowels    # which are present    for i in range(len(string)) :        if (string[i] == 'A' or string[i] == 'a') :            hash[0] = 1;                     elif (string[i] == 'E' or string[i] == 'e') :            hash[1] = 1;                     elif (string[i] == 'I' or string[i] == 'i') :            hash[2] = 1;                     elif (string[i] == 'O' or string[i] == 'o') :            hash[3] = 1;                     elif (string[i] == 'U' or string[i] == 'u') :            hash[4] = 1;                 # Loop to check if there is any vowel    # which is not present in the string    for i in range(5) :        if (hash[i] == 0) :            return 1;                 return 0; # Function to to check that# a string contains all vowelsdef checkIfAllVowelsArePresent(string) :     if (checkIfAllVowels(string)) :        print("Not Accepted");    else :        print("Accepted"); # Driver Codeif __name__ == "__main__" :     string = "aeioubc";    checkIfAllVowelsArePresent(string); # This code is contributed by AnkitRai01
// C# implementation to check that// a String contains all vowelsusing System; class GFG{ // Function to to check that// a String contains all vowelsstatic int checkIfAllVowels(String str){     // Hash Array of size 5    // such that the index 0, 1, 2, 3 and 4    // represent the vowels a, e, i, o and u    int []hash = new int[5];     // Loop the String to mark the vowels    // which are present    for (int i = 0; i < str.Length; i++)    {         if (str[i] == 'A' || str[i] == 'a')            hash[0] = 1;         else if (str[i] == 'E' || str[i] == 'e')            hash[1] = 1;         else if (str[i] == 'I' || str[i] == 'i')            hash[2] = 1;         else if (str[i] == 'O' || str[i] == 'o')            hash[3] = 1;         else if (str[i] == 'U' || str[i] == 'u')            hash[4] = 1;    }     // Loop to check if there is any vowel    // which is not present in the String    for (int i = 0; i < 5; i++)    {        if (hash[i] == 0)        {            return 1;        }    }return 0;} // Function to to check that// a String contains all vowelsstatic void checkIfAllVowelsArePresent(String str){     if (checkIfAllVowels(str) == 1)        Console.Write("Not Accepted\n");    else        Console.Write("Accepted\n");} // Driver Codepublic static void Main(String[] args){    String str = "aeioubc";    checkIfAllVowelsArePresent(str);}} // This code is contributed by 29AjayKumar
<script> // JavaScript implementation to check that// a string contains all vowels // Function to to check that// a string contains all vowelsfunction checkIfAllVowels(str){     // Hash Array of size 5    // such that the index 0, 1, 2, 3 and 4    // represent the vowels a, e, i, o and u    var hash = Array(5).fill(0);     // Loop the string to mark the vowels    // which are present    for (var i = 0; i < str.length; i++) {         if (str[i] == 'A' || str[i] == 'a')            hash[0] = 1;         else if (str[i] == 'E' || str[i] == 'e')            hash[1] = 1;         else if (str[i] == 'I' || str[i] == 'i')            hash[2] = 1;         else if (str[i] == 'O' || str[i] == 'o')            hash[3] = 1;         else if (str[i] == 'U' || str[i] == 'u')            hash[4] = 1;    }     // Loop to check if there is any vowel    // which is not present in the string    for (var i = 0; i < 5; i++) {        if (hash[i] == 0) {            return 1;        }    }    return 0;} // Function to to check that// a string contains all vowelsfunction checkIfAllVowelsArePresent(str){     if (checkIfAllVowels(str))        document.write( "Not Accepted<br>");    else        document.write( "Accepted<br>");} // Driver Codevar str = "aeioubc";checkIfAllVowelsArePresent(str);    </script>
Accepted
 
29AjayKumar
ankthon
importantly
Arrays
Hash
Strings
Arrays
Hash
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Maximum and minimum of an array using minimum number of comparisons
Top 50 Array Coding Problems for Interviews
Stack Data Structure (Introduction and Program)
Introduction to Arrays
Multidimensional Arrays in Java
Given an array A[] and a number x, check for pair in A[] with sum as x (aka Two Sum)
Internal Working of HashMap in Java
Hashing | Set 1 (Introduction)
Hashing | Set 3 (Open Addressing)
Count pairs with given sum