difference between prinf and in cout?

I tried out this question… MARBLEGF Problem - CodeChef

I got AC when i used cin and cout… Submission: CodeChef: Practical coding for everyone
I wanted to increase the speed so I first tried to replace cin and cout with scanf and printf but I got WA with the changes Submisson: CodeChef: Practical coding for everyone . Could anyone please tell me what am I missing here. I did not any other part of the accepted solution. Thanks in advance

In C version, you are using getchar(), try to replace first one with scanf("\n") and remove second one completely and use scanf("%c %d %d\n", &type, &l, &r);

1 Like

Corrected :

Link : http://ideone.com/GTs0ti
4 Likes

thank you @batlista actually it is scanf("\n %c %d %d", &type, &l, &r); …but why any ideas on why should we do so?

thank you for replying…any ideas on why it is behaving like that?

Maybe there is ‘\r’ character - part of line end on Windows or some other whitespace…

After each query as per the input description there should be only one whitespace character and i.e is ‘\n’(newline). Hence, as per your code more than 1 whitespace characters after any query results into wrong input and thereby WA.

1 Like

got 5-6 WA because of this…and wasted three hours…thank you btw…:slight_smile: