Need help in UVa 455 - Periodic Strings

Can someone please tell me what is wrong in my code. Thanks in advance.

This is the link of the problem.

This is my solution code.