It is very simple. You just need to push first word from the first line onto the stack, then push first word from the second line, then do the same for the second words, then to three words, etc.
After that, you need pop remove each element from the stack and push to the second stack to invert the sequence. Then you just pop each item from the second stack and add it to the resulting string.
source share