Decode the string encoded with the given algorithm | Function to decode and print the original string ; To store the decoded string ; Getting the mid element ; Storing the first element of the string at the median position ; If the length is even then store the second element also ; k represents the number of characters that are already stored in the c [ ] ; If string length is odd ; If it is even ; Print the decoded string ; Driver code
def decodeStr ( str , len ) : NEW_LINE INDENT c = [ " " for i in range ( len ) ] NEW_LINE pos = 1 NEW_LINE if ( len % 2 == 1 ) : NEW_LINE INDENT med = int ( len / 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT med = int ( len / 2 - 1 ) NEW_LINE DEDENT c [ med ] = str [ 0 ] NEW_LINE if ( len % 2 == 0 ) : NEW_LINE INDENT c [ med + 1 ] = str [ 1 ] NEW_LINE DEDENT if ( len & 1 ) : NEW_LINE INDENT k = 1 NEW_LINE DEDENT else : NEW_LINE INDENT k = 2 NEW_LINE DEDENT for i in range ( k , len , 2 ) : NEW_LINE INDENT c [ med - pos ] = str [ i ] NEW_LINE if ( len % 2 == 1 ) : NEW_LINE INDENT c [ med + pos ] = str [ i + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT c [ med + pos + 1 ] = str [ i + 1 ] NEW_LINE DEDENT pos += 1 NEW_LINE DEDENT print ( * c , sep = " " ) NEW_LINE DEDENT str = " ofrsgkeeeekgs " NEW_LINE len = len ( str ) NEW_LINE decodeStr ( str , len ) NEW_LINE