#K38747. Robot Return to Origin
Robot Return to Origin
Robot Return to Origin
This problem simulates the movement of a robot on a 2D plane. The robot starts at the origin \( (0,0) \) and follows a sequence of commands. Each command is represented by one of the characters:
- U: Move up by one unit (increase \( y \) coordinate by 1).
- D: Move down by one unit (decrease \( y \) coordinate by 1).
- L: Move left by one unit (decrease \( x \) coordinate by 1).
- R: Move right by one unit (increase \( x \) coordinate by 1).
After executing all commands, you need to determine whether the robot returns to the origin. Formally, if the final position is \( (x, y) \), output True
if \( x = 0 \) and \( y = 0 \), otherwise output False
.
inputFormat
The input consists of a single line from standard input (stdin) that contains a non-empty string of characters. Each character is one of 'U', 'D', 'L', or 'R', representing the robot's commands.
outputFormat
Output to standard output (stdout) a single string: True
if the robot returns to the origin after executing all commands, otherwise False
.
UD
True