What is wrong with my solution …will anyone please tell ?
https://www.codechef.com/viewsolution/29066089
bro you have to use ‘scanf’ in place of ‘cin’,input format is of form 1 2 3 (space separated ) and we use ‘scanf’ for this
check a small change in your code in line 11 make this code run ,sorry link was not working
check this out (correct link)
:-CodeChef: Practical coding for everyone
i have faced this type of problems few times ,
it do make difference , i don’t know why.
i don’t get how scanf() and cin will make the difference
Also the link you provided is wrong i can’t access your solution
He’s probably kind of right … ish Or right for the wrong reasons
Mixing C-style input (getchar()
) with explicitly buffered C++-style input (cin
) is bound to cause problems.
I don’t think that is the reason bro. I have been using cin for all things .this time I even used fastscan for this code. Which is even more optimized than cin
He mixed up cin and getchar() so that’s why he’s getting a WA you mean to say?
He’s not using scanf
anywhere in his solution that I can see, but he is using the C-style getchar
function.
Ordinarily, C-style input (scanf
, getchar
, etc) is buffered, and C++-style input (cin
, etc) is unbuffered, so they can be mixed freely.
However, a call to ios_base::sync_with_stdio(false)
deliberately adds buffering to the C++-style input, meaning that the two styles of input trample all over each other and reading input starts to break down unpredictably.
I am sorry I was referring to earlier thread and forgot to see getchar ;_;.
And yeah i agree with this:
Tf:grimacing:
Dude this is awful way to not accept any solution how would I know that fastinput is giving wrong solution:hot_face:
Ok whatever happened is fine …will now anyone tell me what to do in future in order to avoid such horrible mistakes ?
Here are few pointers-
- run the code at least once on the sample input before submitting
- try not to write code that you don’t think you fully understand
- go through the codes of better coders and learn from them
- whenever you’re adding something new to your code, try to browse the internet to know more about it so that you’re sure that it won’t misfire
NOTE: This list isn’t exhaustive.
Hope this helps.
Read what @ssjgz has written he has clearly explained what was wrong in your code:
You need to learn up more on what fast io actually does to use it.
Sure bro thanks !! I got my mistake now
Sorry for that i got confused when you said scanf there because that is C-style input and it won’t cause problem and yeah you were right