Блог пользователя atulcf24

Автор atulcf24, 2 года назад, По-английски

adding floating point numbers in sqrt make them more accuracte

i submitted a solution containing

 int sq = sqrt(sum);
            if (sq * sq == sum && sq % 2 == 1) cnt++;

although this seems perfectly fine, it doesn't pass the test case listed below

`14'

'1 10 10 100 1 1 10 1 10 2 10 2 10 1`

this must return 3 as the first,fourth and last number fit the condition but returns 2

the issue with it is that sqrt works well with floating point numbers this code fixes the rounding issues

long long sq = (long long)sqrt(sum + 0.5); // Add 0.5 to handle rounding issues
if (sq * sq == sum && sq % 2 == 1) cnt++;

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор atulcf24, история, 2 года назад, По-английски

Any problem set or blogs for interactive type problems would be appreciated

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится