Diff in answers for the online and offline compiler


This code is giving TLE when used with string and cin
But it gives WA when used with char array and scanf
When I ran the same code on offline compiler after using the unlocked testcases … my code gave the correct answer for all the testcases but still it gives the wrong answer on online compiler

hi @prabh1601 i am sharing the editorial solution with you https://ide.codingblocks.com/s/244607 please have a look

If you would see my solution I have written the exact same code … but it gives tle using cin …
My concern never was not knowing the solution for which u are sharing the code …
Come on … just read my properly query already …
I REPEAT … MY CODE IS CORRECT BUT I DON’T KNOW HOW TO USE SCANF SO THAT IT DOESN’T SHOWS WRONG ANSWER AT THE ONLINE COMPILER

@prabh1601 you mentioned that your code is giving TLE on using cin and WA on using scanf, hence i provided the correct solution. For scanf, there is no need for spaces between %s, and for the second argument you have to provide variable address, not variable name so the correct syntax is
scanf("%s%s", &l, &r)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.