WA for An AC for you -CodeWars 1.0

This is a cakewalk problem, but, during the contest I was getting WA for it.
The reason for the WA is, I tried reading the string input using getline(cin,st) instead of just using cin. Then, I went on searching for the difference between getline and cin. I found out that, getline keeps reading the characters until a “\n” is encountered while cin reads the characters until a space is encountered i.e., cin can read words while getline reads lines (hence it can be used to read space seperated strings). So, I’m clear with this but, I still don’t understand how could this make my submission WA because the input strings are anyways gonna be in different lines.

Link to the question:

Link to my WA submission:

Link to my AC submission:

As far as I know there are buffer issues when you are using getline, you need to clear the buffer before an input. I see you have used cin.ignore() before the first input but here you should clear the buffer after every output, and take a fresh input after cleared buffer everytime.

I’ve used cin.ignore() before the first input because theres a new line character left in the input stream because of which it can’t read my string. This issue arises only when I try to use getline immediately after cin… But, that isn’t the case with every iteration.