#K82777. Return to Starting Position
Return to Starting Position
Return to Starting Position
You are given a sequence of moves consisting solely of the characters 'U', 'D', 'L', and 'R'. Each character represents a move by a robot: 'U' for a move up, 'D' for a move down, 'L' for a move left, and 'R' for a move right. The robot starts at the origin, ( (0,0) ), and moves according to the input string.
After processing the entire sequence, the final coordinates ( (x, y) ) are calculated as follows:
$$x = \text{(number of R moves)} - \text{(number of L moves)} $$$$y = \text{(number of U moves)} - \text{(number of D moves)} $$The task is to determine whether the robot returns to its starting position. The output should be (True) if the final position is ( (0, 0) ) and (False) otherwise.
inputFormat
The input is provided via standard input (stdin) as a single line containing a string of moves. The string comprises only the characters 'U', 'D', 'L', and 'R'.
outputFormat
Print (True) (to stdout) if the moves return the robot to the origin ( (0,0) ); otherwise, print (False).## sample
UDLR
True
</p>