Confusion in using Gets v\s Scanf for string in TASHIFT

I am having a problem understanding the difference on result of using gets and scanf in question TASHIFT
here are 2 codes

1 Code1

2 Code2

The only difference being in the 2 codes is that in the 1st code the input is taken using gets and in the other using scanf but the result (which can be seen by scrolling down) are quite contrasting. Please help.

//