Can anyone tell me why the code is showing runtime error ?

Revision en1, by pandey_04, 2021-07-12 07:39:33

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 or see code below. ~~~~~

include <bits/stdc++.h>

using namespace std;

int main() {
int R,C; cin>>R>>C;
string pasture[R];
bool ans = true; for (int i = 0 ; i < R ; i ++) { cin>>pasture[i]; } for (int i = 0 ; i < R ; i ++) { for (int j = 0 ; j < C ; j ++) { if (pasture[i][j] == 'S') { if (pasture[i][j-1] == 'W') { ans = false; break; } else if (pasture[i][j+1] == 'W') { ans = false; break; }
else if (pasture[i-1][j] == 'W') { ans = false; break; }
else if (pasture[i+1][j] == 'W') { ans = false; break; } } } if (!ans) break; } if (ans) { cout<<"Yes\n"; for (int i = 0 ; i < R ; i ++) { replace(pasture[i].begin(),pasture[i].end(),'.','D'); cout<<pasture[i]<<"\n"; } } else cout<<"No"; return 0; } ~~~~~

Tags #c++, #implementation, #doubt

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English pandey_04 2021-07-12 07:41:41 13
en2 English pandey_04 2021-07-12 07:40:20 1242
en1 English pandey_04 2021-07-12 07:39:33 1935 Initial revision (published)