Modify string by increasing each character by its distance from the end of the word | Function to transform and return the transformed word ; Stores resulting word ; Iterate over the word ; Add the position value to the letter ; Convert it back to character ; Add it to the string ; Function to transform the given string ; Size of string ; Stores resultant string ; Iterate over given string ; End of word is reached ; print ( s [ j : j + i ] ) Append the word ; For the last word ; Driver code ; Given string ; Function call
def util ( sub ) : NEW_LINE INDENT n = len ( sub ) NEW_LINE i = 0 NEW_LINE ret = " " NEW_LINE while i < n : NEW_LINE INDENT t = ( ord ( sub [ i ] ) - 97 ) + n - 1 - i NEW_LINE ch = chr ( t % 26 + 97 ) NEW_LINE ret = ret + ch NEW_LINE i = i + 1 NEW_LINE DEDENT return ret NEW_LINE DEDENT def manipulate ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE i = 0 NEW_LINE j = 0 NEW_LINE res = " " NEW_LINE while i < n : NEW_LINE INDENT if s [ i ] == ' ▁ ' : NEW_LINE INDENT res += util ( s [ j : j + i ] ) NEW_LINE res = res + " ▁ " NEW_LINE j = i + 1 NEW_LINE i = j + 1 NEW_LINE DEDENT else : NEW_LINE INDENT i = i + 1 NEW_LINE DEDENT DEDENT res = res + util ( s [ j : j + i ] ) NEW_LINE print ( res ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " acm ▁ fkz " NEW_LINE manipulate ( s ) NEW_LINE DEDENT