Help needed in Runtime Error

Kindly Someone help me with my solution. I am getting Runtime Error. I have rewritten the code several times but still no change .
Error Page | CodeChef this is the link to the solution.The problem link is also attached with the solution
Problem link->Contest Page | CodeChef

@ssjgz Sir,I am tagging you since last time also you helped. I have used the compiler flags from that blogpost you made earlier but still no help .

Anyone else if you can kindly help…
Thank you.

1 Like

Your solution page is showing invalid solution id

The link I referred
The type of path[i][j] is string , and the type of character[i][j] is char , you cannot do type conversion like this, One of the reason of Runtime error
You can correct it by character[i].substr(j,1);

Your code ACfied . Have fun :slight_smile:

Thanks Sir for taking out time to help me. Well, I dont understand the reason of this error. When I am running it on the sample test cases there is no such problem. And that statement is executed every time whatever input I may give. I ran it in codechef compiler…it didnt give any error …even I used compiler flags still no error…If I normally try to concatenate a character to a string that executes without any error…Would like to comment any further regarding this?

1 Like

Maybe this could help C++ character concatenation with std::string behavior. Please explain this - Stack Overflow
And actually I am not that good to answer this query of yours.

Can you send the link to the post containing compiler flags

Yes sure,> this is the link

All the string handling concatenation stuff is fine, I think - if I were to guess, I’d say that the problem is mostly likely that a) the test input has extra whitespace (it’s an external contest, after all!) and b) your program can’t handle this.

For example, consider this testcase (it’s simply two copies of the sample test input, with an extra space added after the second 1 1) - this will cause your program to crash as you are not ignoring the rest of the line correctly.

To fix it, try either:

  • replacing cin.ignore() with cin.ignore(std::numeric_limits<streamsize>::max(), '\n'); or
  • taking part of @dhrub_kumar’s solution that reads input (his is whitespace-insensitive as it just reads in strings, rather than lines).

Sir, Lot of thanks to you as well.I am certain that the error was due to some extra space after the input data. Thank you Sir.

1 Like