#K50702. Return to Origin
Return to Origin
Return to Origin
You are given a string representing the moves of a robot. Each character of the string can be one of 'U', 'D', 'L', or 'R', representing moves Up, Down, Left and Right respectively. The robot starts at the origin (0, 0). Your task is to determine whether the robot returns to the origin after performing all the moves.
In mathematical terms, let \(x\) and \(y\) represent the robot's coordinate axes. The effect of each move is as follows:
- 'U': \(y \leftarrow y+1\)
- 'D': \(y \leftarrow y-1\)
- 'L': \(x \leftarrow x-1\)
- 'R': \(x \leftarrow x+1\)
The robot returns to the origin if and only if \(x = 0\) and \(y = 0\) after processing the entire string.
Input is taken from stdin and output should be printed to stdout.
inputFormat
The input consists of a single line containing a string moves
(which may be empty), representing the sequence of moves of the robot.
outputFormat
Print a single line with True
if the robot returns to the origin after processing all moves; otherwise, print False
.
UDLR
True