The title

You are given a string s whose subscripts start at 0 and whose even subscripts are lowercase letters and odd subscripts are numbers.

Define a function shift(c, x), where c is a character and x is a number, that returns the x character after c in the alphabet.

For example, shift(‘a’, 5) = ‘f’ and Shift (‘x’, 0) = ‘x’. For every odd subscript I, you need to replace the number s[I] with shift(s[i-1], s[I]).

After replacing all the numbers, return the string s. They guarantee that shift(s[I -1], s[I]) does not exceed ‘z’.

 

Example 1: Input: s = "a1C1E1" Output: "abcdef" Explanation: The result is as follows: S [1] - > shift (' a ', 1) = 'b' s [3] - > shift (' c ', 1) = 'd' s [5] - > shift (' e ', 1) = 'f' example 2: input: s = "a1b2c3d4e" output: "Abbdcfdhe" explanation: The numbers are replaced as follows:  - s[1] -> shift('a',1) = 'b' - s[3] -> shift('b',2) = 'd' - s[5] -> shift('c',3) = 'f' - s[7] -> shift('d',4) = 'h'Copy the code

Tip:

1 <= S. length <= 100 s Contains only lower-case letters and digits. For I at all odd indices, shift(s[I -1], s[I]) <= ‘z’.

Their thinking

Class Solution: def replaceDigits(self, s: STR) -> sList = list(s) for index, val in enumerate(sList): val = str(val) if val.isnumeric(): # ord: convert characters to ASCII counterparts C = CHR (ord(sList[index-1])+int(val)) sList[index] = c return "". Join (sList) if __name__ == '__main__': s = "a1c1e1" ret = Solution().replaceDigits(s) print(ret)Copy the code