Description
The successor to a string can be calculated by applying the following rules:
- Ignore the nonalphanumerics unless there are no alphanumerics, in this case, increase the rightmost character in the string.
- The increment starts from the rightmost alphanumeric.
- Increase a digit always results in another digit ('0' -> '1', '1' -> '2' ... '9' -> '0').
- Increase a upper case always results in another upper case ('A' -> 'B', 'B' -> 'C' ... 'Z' -> 'A').
- Increase a lower case always results in another lower case ('a' -> 'b', 'b' -> 'c' ... 'z' -> 'a').
- If the increment generates a carry, the alphanumeric to the left of it is increased.
- Add an additional alphanumeric to the left of the leftmost alphanumeric if necessary, the added alphanumeric is always of the same type with the leftmost alphanumeric ('1' for digit, 'A' for upper case and 'a' for lower case).
Input
There are multiple test cases. The first line of input is an integer T
Each test case contains a nonempty string s and an integer 1 ≤ n ≤ 100. The string s
Output
For each test case, output the next n successors to the given string s
Sample Input
4 :-( 1 cirno=8 2 X 3 /**********/ 4
Sample Output
:-) cirno=9 cirnp=0 Y Z AA /**********0 /**********1 /**********2 /**********3
有字母和数字的无视其他字符,而没有的时候从最右边开始。其实就是做加法和进位。
温故而知新