0
What did i do wrong i fail 1 test and when i try separated it outputs 672 .Why?
2D Map You're given a representation of a 5x5 2D map, and if you can only move left, right, up, or down, determine how many moves you would have to make to get between two points on the map. Task: Determine the total number of moves that are needed between two points on a map. The points that you move between are marked with a P and the spaces in between are marked with X. Input Format: A string that represents the 2D space starting at the top left. Each level from top to bottom is separated by a comma. Output Format: An integer that represents the total number of moves that you had to make. Sample Input: XPXXX,XXXXX,XXXXX,XXXPX,XXXXX Sample Output: 5 https://code.sololearn.com/cwwmc0kPMv7a/?ref=app
1 Answer
+ 2
std::string::size function return size_t type, you try compare this with the x that is int type.
size_t is unsigned long long int (unsigned int of 64 bits).
The solutions:
1. change the type of x from int to size_t or
2. cast the return value of std::string::size to int.
The 1st solution recommend