Sunday, September 7, 2014

SPOJ 400. To and Fro

This is an implementation task so we need to think the easiest and the most understandable method. I suggest trying to recover the matrix then the string itself. We can do it in the following way. The first element of the given string S[0] is the first element of an array A[1][1] . Now we need to move according to the direction, and every time write the current char in the current spot, whenever we reached the end (or the beginning) of the array we need to flip the direction, get down to the next row and keep on going. Check out the source code for a better understanding.


       FULL SOURCE CODE

No comments:

Post a Comment