#C11252. Return to Origin
Return to Origin
Return to Origin
You are given a sequence of moves represented by a string, where each character denotes a move in one of the four cardinal directions: 'L' (left), 'R' (right), 'U' (up), and 'D' (down). The task is to determine if these moves bring you back to the origin point (0, 0).
In mathematical terms, let (x) and (y) denote the coordinates. Initially, (x = 0) and (y = 0). For each move:
- 'L' decrements (x) by 1.
- 'R' increments (x) by 1.
- 'U' increments (y) by 1.
- 'D' decrements (y) by 1.
You need to check whether after performing all the moves, the condition $$x = 0 \text{ and } y = 0$$ holds. Output "Yes" if it does, and "No" otherwise.
inputFormat
The input is provided via standard input (stdin). It consists of a single line containing a string (S) that represents the sequence of moves.
outputFormat
Output a single line to standard output (stdout) containing "Yes" if the sequence of moves brings you back to the origin, otherwise output "No".## sample
LLRR
Yes