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

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

CF is showing runtime error on test 3 because of out of bounds which I think is not true because the code is working fine in local IDE, It's just that the input won't process without pressing enter in local IDE. Why is that ? maybe that's why the input is not getting accepted and runtime error is showing. Also, I think the out of bounds is not legit because that statement is inside 'if' block, so it just won't get executed if the statement is not true. Please have a look at at and tell me why this code is not executing for test 3. Thank you in advance. click Code Link

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

»
3 года назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

All two-dimensional indices should be in the $$$[0,R-1]$$$ and $$$[0,C-1]$$$ bounds of the rectangle. Since the loop variables $$$i$$$ and $$$j$$$ are limited to these bounds, at least one of the neighboring values $$$i-1$$$, $$$i+1$$$, $$$j-1$$$, and $$$j+1$$$ is out-of-bound at any boundary cell of the rectangle. You should add a validation condition when using any of these value so as to avoid this error.

For example, the marked condition at line 24 should be rewritten as

if (i > 0 and pasture[i-1][j] == 'W')