#K44312. Robot Return to Origin
Robot Return to Origin
Robot Return to Origin
The task is to determine if a robot returns to its starting point after performing a sequence of moves. The robot begins at the origin, \( (0,0) \), and executes a series of instructions represented by a string. Each character in the string is one of the following: 'U' (up), 'D' (down), 'L' (left), and 'R' (right). The movement alters its position as follows:
\( x = x + (\#\,R - \#\,L) \) and \( y = y + (\#\,U - \#\,D) \).
If after executing all moves the robot is back at \( (0,0) \), output True
; otherwise, output False
.
inputFormat
The input consists of a single line from standard input containing a string that represents the robot's sequence of moves.
outputFormat
Output a single line to standard output with the boolean value True
if the robot returns to the origin; otherwise, output False
.
UD
True