# Program to accept a Strings which contains all the Vowels

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 u

Input: S = “ABeeIghiObhkUul”
Output: Accepted
Since S contains all vowels a, e, i, o and u

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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++

 `// C++ implementation to check that ` `// a string contains all vowels ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function to to check that ` `// a string contains all vowels ` `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 = { 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 = 1; ` ` `  `        ``else` `if` `(str[i] == ``'E'` `|| str[i] == ``'e'``) ` `            ``hash = 1; ` ` `  `        ``else` `if` `(str[i] == ``'I'` `|| str[i] == ``'i'``) ` `            ``hash = 1; ` ` `  `        ``else` `if` `(str[i] == ``'O'` `|| str[i] == ``'o'``) ` `            ``hash = 1; ` ` `  `        ``else` `if` `(str[i] == ``'U'` `|| str[i] == ``'u'``) ` `            ``hash = 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 vowels ` `int` `checkIfAllVowelsArePresent(string str) ` `{ ` ` `  `    ``if` `(checkIfAllVowels(str)) ` `        ``cout << ``"Not Accepted\n"``; ` `    ``else` `        ``cout << ``"Accepted\n"``; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``string str = ``"aeioubc"``; ` `    ``checkIfAllVowelsArePresent(str); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation to check that ` `// a String contains all vowels ` ` `  `class` `GFG ` `{ ` ` `  `// Function to to check that ` `// a String contains all vowels ` `static` `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 vowels ` `static` `void` `checkIfAllVowelsArePresent(String str) ` `{ ` ` `  `    ``if` `(checkIfAllVowels(str) == ``1``) ` `        ``System.out.print(``"Not Accepted\n"``); ` `    ``else` `        ``System.out.print(``"Accepted\n"``); ` `} ` ` `  `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``String str = ``"aeioubc"``; ` `    ``checkIfAllVowelsArePresent(str); ` `} ` `} ` ` `  `// This code is contributed by 29AjayKumar `

## Python3

 `# Python3 implementation to check that  ` `# a string contains all vowels  ` ` `  `# Function to to check that  ` `# a string contains all vowels  ` `def` `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 vowels  ` `def` `checkIfAllVowelsArePresent(string) :  ` ` `  `    ``if` `(checkIfAllVowels(string)) : ` `        ``print``(``"Not Accepted"``);  ` `    ``else` `: ` `        ``print``(``"Accepted"``);  ` ` `  `# Driver Code  ` `if` `__name__ ``=``=` `"__main__"` `:  ` ` `  `    ``string ``=` `"aeioubc"``;  ` `    ``checkIfAllVowelsArePresent(string);  ` ` `  `# This code is contributed by AnkitRai01 `

## C#

 `// C# implementation to check that ` `// a String contains all vowels ` `using` `System; ` ` `  `class` `GFG ` `{ ` ` `  `// Function to to check that ` `// a String contains all vowels ` `static` `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``; ` ` `  `    ``// 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 = 1; ` ` `  `        ``else` `if` `(str[i] == ``'E'` `|| str[i] == ``'e'``) ` `            ``hash = 1; ` ` `  `        ``else` `if` `(str[i] == ``'I'` `|| str[i] == ``'i'``) ` `            ``hash = 1; ` ` `  `        ``else` `if` `(str[i] == ``'O'` `|| str[i] == ``'o'``) ` `            ``hash = 1; ` ` `  `        ``else` `if` `(str[i] == ``'U'` `|| str[i] == ``'u'``) ` `            ``hash = 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 vowels ` `static` `void` `checkIfAllVowelsArePresent(String str) ` `{ ` ` `  `    ``if` `(checkIfAllVowels(str) == 1) ` `        ``Console.Write(``"Not Accepted\n"``); ` `    ``else` `        ``Console.Write(``"Accepted\n"``); ` `} ` ` `  `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` `    ``String str = ``"aeioubc"``; ` `    ``checkIfAllVowelsArePresent(str); ` `} ` `} ` ` `  `// This code is contributed by 29AjayKumar `

Output:

```Accepted
```

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : 29AjayKumar, AnkitRai01

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.