black_moon_'s blog

By black_moon_, history, 4 years ago, In English

Hello All, I was trying to do an old problem Problem Link where I got the wrong answer for a testcase while submitting the solution and I ran the same testcase on few other compilers, I got the correct answer. Here are the links to results from ideone, codeforces, geeksforgeeks and (unable to attach image) for the solution Solution Link .

Please help if anyone knows the reason.
  • Vote: I like it
  • -7
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it
cout << int(ans) << endl;

You are rounding floating point values...

If answer is integer, so the double should be around an integer, then to get best rounding, use int(ans+0.5);