Digits whose alphabetic representations are jumbled in a given string | Function to convert the jumbled into digits ; Strings of digits 0 - 9 ; Initialize vector ; Initialize answer ; Size of the string ; Traverse the string ; Update the elements of the vector ; Print the digits into their original format ; Return answer ; Driver Code
def finddigits ( s ) : NEW_LINE INDENT num = [ " zero " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " ] NEW_LINE arr = [ 0 ] * ( 10 ) NEW_LINE ans = " " NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( s [ i ] == ' z ' ) : NEW_LINE INDENT arr [ 0 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' w ' ) : NEW_LINE INDENT arr [ 2 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' g ' ) : NEW_LINE INDENT arr [ 8 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' x ' ) : NEW_LINE INDENT arr [ 6 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' v ' ) : NEW_LINE INDENT arr [ 5 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' o ' ) : NEW_LINE INDENT arr [ 1 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' s ' ) : NEW_LINE INDENT arr [ 7 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' f ' ) : NEW_LINE INDENT arr [ 4 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' h ' ) : NEW_LINE INDENT arr [ 3 ] += 1 NEW_LINE DEDENT if ( s [ i ] == ' i ' ) : NEW_LINE INDENT arr [ 9 ] += 1 NEW_LINE DEDENT DEDENT arr [ 7 ] -= arr [ 6 ] NEW_LINE arr [ 5 ] -= arr [ 7 ] NEW_LINE arr [ 4 ] -= arr [ 5 ] NEW_LINE arr [ 1 ] -= ( arr [ 2 ] + arr [ 4 ] + arr [ 0 ] ) NEW_LINE arr [ 3 ] -= arr [ 8 ] NEW_LINE arr [ 9 ] -= ( arr [ 5 ] + arr [ 6 ] + arr [ 8 ] ) NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT for j in range ( arr [ i ] ) : NEW_LINE INDENT ans += chr ( ( i ) + ord ( '0' ) ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = " owoftnuoer " NEW_LINE print ( finddigits ( s ) ) NEW_LINE DEDENT