Modify the string such that it contains all vowels at least once | C # implementation of the above approach ; All vowels ; List to store distinct vowels ; If length of String is less than 5 then always Impossible ; Storing the distinct vowels in the String by checking if it in the list of String and not in the list of distinct vowels ; Storing the vowels which are not present in the String ; No replacement needed condition ; Replacing the characters to get all Vowels ; Copy th rest of the string ; Driver Code
using System ; using System . Collections ; class GFG { static bool find ( char [ ] x , char c ) { for ( int i = 0 ; i < x . Length ; i ++ ) if ( x [ i ] == c ) return true ; return false ; } static bool find ( ArrayList v , char c ) { for ( int i = 0 ; i < v . Count ; i ++ ) if ( ( char ) v [ i ] == c ) return true ; return false ; } static void addAllVowel ( string str ) { char [ ] x = { ' A ' , ' E ' , ' I ' , ' O ' , ' U ' } ; ArrayList y = new ArrayList ( ) ; int length = str . Length ; if ( length < 5 ) Console . Write ( " Impossible " ) ; else { for ( int i = 0 ; i < length ; i ++ ) { if ( find ( x , str [ i ] ) && ! find ( y , str [ i ] ) ) y . Add ( str [ i ] ) ; } ArrayList z = new ArrayList ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) if ( ! find ( y , x [ i ] ) ) z . Add ( x [ i ] ) ; if ( z . Count == 0 ) Console . Write ( str ) ; else { int cc = 0 ; ArrayList y1 = new ArrayList ( ) ; string ans = " " ; for ( int i = 0 ; i < length ; i ++ ) { if ( find ( x , str [ i ] ) && ! find ( y1 , str [ i ] ) ) { ans += str [ i ] ; y1 . Add ( str [ i ] ) ; } else { ans += ( char ) z [ cc ] ; cc ++ ; } if ( cc == z . Count ) { for ( int j = i + 1 ; j < length ; j ++ ) ans += str [ j ] ; break ; } } Console . Write ( ans ) ; } } } public static void Main ( string [ ] args ) { string str = " ABCDEFGHI " ; addAllVowel ( str ) ; } }