This problem is modified from 13648 - Text maze.
There will be a 2D map composed of only 5 kinds of alphabets, which are a, b, c, d, and e.
First, given the position P (e.g., (2, 3)), you must find the smallest(Using ASCII code) char around it (should be at most eight choices).
Note that if there are duplicated chars, please choose the element with larger index:
Next,
if the summation is 'a', please move your current position to the left;
if the summation is 'b', please move your current position to the right;
if the summation is 'c', please move your current position to the up;
if the summation is 'd', please move your current position to the down;
if the summation is 'e', move your current position into the chosen char, and from now on, you have to find the biggest char, vise versa(If the current mode is to find the biggest char, start to find the smallest one).
There are two terminal situations:
(1) Your next step is outside the map (Next movement is illegal).
(2) You reach the given steps.
Once the whole process ends, please print the texts you've visited.
There will be 4 parts for the input:
(1) The size of the map, n. (5 <= n <= 100)
(2) The maximum steps in the process, S. (1 <= S <= n**2 )
(3) The initial position(x, y).It is guaranteed that it is on the map.
(4) The text map with size n*n.
All of them are separated by a '\n'.
The texts you've traversed.
Note that you dont' have to print "\n" at the end.