#C3534. Return to Origin
Return to Origin
Return to Origin
You are given a string representing a sequence of moves, where each character in the string indicates a move in one of the four cardinal directions:
- U: Move up.
- D: Move down.
- L: Move left.
- R: Move right.
Your task is to determine whether the given sequence of moves returns to the origin \((0,0)\). That is, after executing all moves, you should be back at \(x = 0\) and \(y = 0\).
For example, if the input move sequence is "UDLR", then after processing these moves the final position is \((0,0)\). However, for the sequence "UUDLLR", the final position is \((-1,1)\) and thus it does not return to the origin.
inputFormat
The input consists of a single line containing a non-empty string of characters. Each character will be one of U
, D
, L
, or R
representing a move.
outputFormat
Output a single line: True
if the sequence of moves returns to the origin \((0,0)\), otherwise output False
.
UDLR
True
</p>