PLEASE HELP VTREE-MAY LOC

I travel from leaves to root and used KMP to find string pattern in my program.

When I used cin in line 46 I get expected output

Link: By0PQu - Online C++0x Compiler & Debugging Tool - Ideone.com

But since it is clearly mentioned in question using cin will give TLE I get 4 TLE in 2nd Subtask

Solution Link: CodeChef: Practical coding for everyone

So I used scanf instead of cin in line 45 but I get runtime error or all zeros in output

Link: 3DEx7V - Online C++0x Compiler & Debugging Tool - Ideone.com

Problem Link : CodeChef: Practical coding for everyone

Actually after reading the string your code was reading the newline as the character in ta. So, ta[0] was actually a newline which was giving you the runtime error. What I did in your code is that I made a dummy variable “ccc” and read the newline before it entered the loop to input the character. This solved the problem :slight_smile:

Code: ePBE8n - Online C++0x Compiler & Debugging Tool - Ideone.com

Actually, one piece of advice would be to use cin and cout only but the the following lines of code just in the beginning of main function for fast I/O.

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

Hope this helped :slight_smile:

1 Like

what is wrong with this solution , just giving wa in 1 testcase??

https://www.codechef.com/viewsolution/13906095

Thanks a lot :slight_smile:

Happy to help :slight_smile: