Robot#87

Robot (Editorial)

Written by @Tuncay_Pashayev.

In this problem we have to find the number of different cells that robot has visited.

For this problem we'll use set to find different cells. We mustn't add the cell that we have already visited and set is deleting duplicated elements. If we are moving to right, we'll increase robot's current position by . Otherwise, if we are moving to left, we'll decrease robot's current position by . After these operations, we'll add our position to set.

Implementation

set <int> s;

Creating a set called .

if (move[i] == 'S')
    continue;

If move[i] is equals to , then robot is not moving anywhere.

else if (move[i] == 'R')
    position++;

Otherwise, if move[i] is equals to , then we are moving to right and increasing robot's current position by .

else if (move[i] == 'L')
    position--;

Otherwise, if move[i] is equals to , then we are moving to left and decreasing robot's current position by .

s.insert(position);

Adding robot's current position to set.

cout<<s.size();

Printing the size of set.