Finding the number of substrings from a given string

Problem-AUSAG Problem - CodeChef
I really cant find the problem in my code. I have already spent 2 weeks trying to fiigure out why the submission is giving me WA.
My code- substring.cxx - Pastebin.com