Reorder characters of a string to valid English representations of digits | C # program to implement the above approach ; Function to construct the original set of digits from the string in ascending order ; Store the unique characters corresponding to word and number ; Store the required result ; Store the frequency of each character of S ; Traverse the unique characters ; Store the count of k [ i ] in S ; Traverse the corresponding word ; Decrement the frequency of characters by x ; Append the digit x times to ans ; Sort the digits in ascending order ; Driver Code ; Given string , s ; Function Call
using System ; using System . Collections . Generic ; class GFG { static string construct_digits ( string s ) { char [ ] k = { ' z ' , ' w ' , ' u ' , ' x ' , ' g ' , ' h ' , ' o ' , ' f ' , ' v ' , ' i ' } ; string [ ] l = { " zero " , " two " , " four " , " six " , " eight " , " three " , " one " , " five " , " seven " , " nine " } ; int [ ] c = { 0 , 2 , 4 , 6 , 8 , 3 , 1 , 5 , 7 , 9 } ; List < string > ans = new List < string > ( ) ; Dictionary < char , int > d = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( ! d . ContainsKey ( s [ i ] ) ) d [ s [ i ] ] = 0 ; d [ s [ i ] ] += 1 ; } for ( int i = 0 ; i < k . Length ; i ++ ) { int x = 0 ; if ( d . ContainsKey ( k [ i ] ) ) x = d [ k [ i ] ] ; for ( int j = 0 ; j < l [ i ] . Length ; j ++ ) { if ( d . ContainsKey ( l [ i ] [ j ] ) ) d [ l [ i ] [ j ] ] -= x ; } ans . Add ( ( ( c [ i ] ) * x ) . ToString ( ) ) ; } ans . Sort ( ) ; string str = ( String . Join ( " " , ans . ToArray ( ) ) ) ; return str . Replace ( "0" , " " ) ; } public static void Main ( string [ ] args ) { string s = " fviefuro " ; Console . WriteLine ( construct_digits ( s ) ) ; } }