# Change the string so that it contains all vowels at least once

|

Examples :

`  Input : str = "ABCDEFGHI"  Output : AOUDEFGHI There are already 3 Vowels present in the string A, E, I we just change B and C to O and U respectively.  Input : str = "ABC"  Output : IMPOSSIBLE `

Approach: since there are only 5 vowels A, E, I , O, U. So, if the string length is less than 5, this is always impossible.
For a line longer than 5, this is always possible. Just loop over each character and replace it with a vowel that isn’t on the string. If the current character is a vowel, and if it has not been visited before, then we will not change the character to a vowel. If all vowels are already present at the beginning, then there is no need to change any character.

Below is the implementation of the above approach:

C++

 ` // C++ implementation of the above approach ` ` # include "bits / stdC++. h" ` ` using ` ` namespace ` ` std; `   ` void ` ` addAllVowel (string str) ` ` {` ` ` ` // all vowels ` ` char ` ` x [] = {` ` ’A’ ` `, ` ` ’E’ ` `, ` `’ I’ ` `, ` ` ’O’ ` `, ` `’ U’ ` `}; `   ` // List for storing different vowels ` ` ` ` vector "` ` char ` `" y; ` ` int ` ` length = str. length (); `   ` // if the line length is less than 5 ` ` ` ` // then always impossible ` ` if ` ` (length "5) ` ` cout "& lt; ` ` "Impossible" ` ` "& lt; endl; ` ` else `  ` ` ` {` ` ` ` / / Keeping different vowels in the string ` ` // checking if the list contains a string and not ` ` // in a list of different vowels ` ` for ` ` (` ` int ` ` i = 0; i "length; i ++) ` ` {` ` if ` ` (find (x, x + 5, str [i])! = x + 5 and ` ` find (y. begin (), y.end (), str [i]) == y.end ()) ` ` y.push_back (str [i]); ` `} `   ` ` ` // Save vowels ` ` // missing in line ` ` vector "` ` char ` `" z; ` ` for ` ` (` ` int ` ` i = 0; i "5; i ++) ` ` ` ` if ` ` (find (y.begin (), ` ` y.end (), x [i]) == y.end ()) ` ` z.push_back (x [i]); `   ` // No replacement required ` ` ` ` if ` ` (z.empty ()) ` ` ` ` cout "& lt; str "& lt; endl; ` ` else `  ` ` ` {` ` ` ` int ` ` cc = 0; ` ` vector "` ` char ` `" y; `   ` // Replace characters to get all vowels ` ` ` ` for ` ` (` ` int ` ` i = 0; i "length; i ++) ` ` {` ` if ` ` (find (x, x + 5, str [i])! = x + 5 and ` ` find (y.begin (), y.end (), ` ` str [i]) == y.end ()) ` ` y.push_back (str [i]); ` ` else `  ` ` ` {` ` ` ` str [i] = z [cc]; ` ` cC++; ` `} ` ` if ` ` (cc == z.size ()) ` ` break ` `; ` `} ` ` cout "& lt; str "& lt; endl; ` `} ` `} ` `} `   ` // Driver code ` ` int ` ` main (` ` int ` ` argc, ` ` char ` ` const ` ` * argv []) ` ` {` ` ` ` string str = ` ` "ABCDEFGHI" ` `; ` ` addAllVowel (str); ` ` return ` ` 0; ` `} `   ` // This code is provided ` ` // sanjeev2552 `

python3

 ` # Python implementation of the above approach `   ` s ` ` = ` ` "ABCDEFGHI" `   ` # convert string to list ` ` S ` ` = ` ` list ` ` (s) ` ` `  ` ` ` # All vowels ` ` x = [ "A" , "E" , "I" , "O" , "U " ] ``      # List for storing different vowels y = []  le = len (S) if (le & lt;  5 ):   # if the line length is less than 5, then always # Not possible print ( "Impossible" ) else : # Storing different vowels in a string # checking if a string is in the list and not # in the list of different vowels   for i in range (le): if (S [i] in x and S [i] not in y):   y.append (S [i])   # Storing vowels that are not on the line z = []   for i in range ( 5 ):   if (x [i] not in y): z.append (x [i]) if ( len (z) = = 0 ):   # No need to replace condition print (s) else :   cc = 0 y = []   # Replace characters to get all vowels for i in range (le): if (S [i] in x and S [i] not in y): y.append (S [i])   else : S [i] = z [cc] cc + = 1 if (cc = = len (z)): break   print ( * S, sep = " ") `

Exit:

` AOUDEFGHI `

## Shop Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$ Best laptop for Zoom

\$499 Best laptop for Minecraft

\$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method