Minimum cost to convert given string to consist of only vowels | C # program for the above approach ; Function to find the minimum cost ; Store vowels ; Loop for iteration of string ; Loop to calculate the cost ; Add minimum cost ; Driver Code ; Given string ; Function call
using System ; using System . Collections . Generic ; class GFG { static int min_cost ( string st ) { string vow = " aeiou " ; int cost = 0 ; for ( int i = 0 ; i < st . Length ; i ++ ) { List < int > costs = new List < int > ( ) ; for ( int j = 0 ; j < 5 ; j ++ ) costs . Add ( Math . Abs ( st [ i ] - vow [ j ] ) ) ; int minx = Int32 . MaxValue ; foreach ( int x in costs ) { if ( x < minx ) { minx = x ; } } cost += minx ; } return cost ; } public static void Main ( ) { string str = " abcde " ; Console . WriteLine ( min_cost ( str ) ) ; } }