WA in CHFCHK

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.

check it guys @shim98 @avi_9314

1 Like

i don’t get how scanf() and cin will make the difference

1 Like

Also the link you provided is wrong i can’t access your solution

He’s probably kind of right … ish :slight_smile: Or right for the wrong reasons :slight_smile:

Mixing C-style input (getchar()) with explicitly buffered C++-style input (cin) is bound to cause problems.

3 Likes

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.

2 Likes

I am sorry I was referring to earlier thread and forgot to see getchar ;_;.
And yeah i agree with this:

1 Like

https://www.codechef.com/viewsolution/29086559
I commented the fio statement and got AC

See my posts :slight_smile: Here’s your corrected solution: CodeChef: Practical coding for everyone

2 Likes

Tf​:grimacing::grimacing::grimacing:

Dude this is awful way to not accept any solution :unamused::unamused::unamused:how would I know that fastinput is giving wrong solution​:hot_face::hot_face::face_with_thermometer:

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. :slight_smile:

3 Likes

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.

3 Likes

Sure bro thanks !! I got my mistake now :love_you_gesture:

1 Like

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 :slight_smile:

1 Like