#K72102. Robot Return to Origin
Robot Return to Origin
Robot Return to Origin
A robot is initially positioned at the origin ((0,0)) in a 2D Cartesian plane. It is given a sequence of moves represented by a string consisting solely of the characters 'U' (up), 'D' (down), 'L' (left), and 'R' (right). With each move, the robot moves one unit in the corresponding direction. Mathematically, the robot's position ((x,y)) is updated as follows:
[
(x,y) \to \begin{cases}
(x, y+1) & \text{if move is 'U'}\
(x, y-1) & \text{if move is 'D'}\
(x-1, y) & \text{if move is 'L'}\
(x+1, y) & \text{if move is 'R'}
\end{cases}
]
Your task is to determine whether the robot returns to the origin ((0,0)) after executing all the moves. If it does, print YES
; otherwise, print NO
.
inputFormat
Input is provided via standard input (stdin) as a single line containing the string (S). This string denotes the sequence of moves.
outputFormat
Output a single line to standard output (stdout) containing either YES
if the robot returns to the origin, or NO
otherwise.## sample
UDLR
YES