Here are two of my submissions, exactly same, one in C and the other in C++. The submission in C++ gives an AC verdict while the submission in C gives a WA verdict. The code was originally written in C. Can anyone please point out the error? I’m unable to find the problem because the two submissions are EXACTLY SAME. (only iostream line was different)
yeah, TC’s were same @vijju123 as most of the people’s solution are 100% similar to mine. It’s just if and else lol. Wasted 2 hours figuring out error in my logic lol
Well, got the error guys. You’re declaring variables inside the loop which sometimes don’t work well in C Language. Look at the solution if declared outside your code works fine in C. Solution
Simply, iterating through all the possibilities where an error should occur and that was the line which was causing the error when declared outside, works like a charm.
Well, now I got the cause. That’s a standard difference. In C99, the rules are the same as in C++. Default GCC uses C89 with some extensions. For C89, you must declare all of your variables at the beginning of a scope block.
Thanks, never knew that it makes a difference nowadays.
I had read that nowadays it doesn’t matter :
Maybe I was wrong lol.
I’ll declare everything global now
Most of the compiler use C99 but still some Online judges use C89 as gcc. Declaring global will also help you to use more space for allocation. Better to use C++, it also has some inbuilt implementations to make the job easy.