#C4954. RoboBuddy Sequence Validation
RoboBuddy Sequence Validation
RoboBuddy Sequence Validation
You are given a sequence of commands that direct the movement of a robot named RoboBuddy. The commands are represented by the characters 'L', 'R', 'U', and 'D', indicating moves left, right, up, and down respectively. Your task is to determine whether, after performing all the commands in sequence, RoboBuddy returns to the starting point at the origin (0,0).
The movement can be represented in the Cartesian coordinate system as follows:
- 'L' decrements the x-coordinate by 1.
- 'R' increments the x-coordinate by 1.
- 'U' increments the y-coordinate by 1.
- 'D' decrements the y-coordinate by 1.
The condition for success is that after executing all commands, the coordinates satisfy:
\( x = 0 \) and \( y = 0 \).
Write a program that reads a single line from standard input representing the command sequence and prints True
if RoboBuddy returns to the origin, otherwise prints False
.
inputFormat
The input consists of a single line containing a non-empty string s
which consists of the characters 'L', 'R', 'U', and 'D'. It is possible that the string is empty, which means no movements are performed.
outputFormat
Output a single line to standard output: True
if RoboBuddy returns to the origin (0, 0) after executing the movements, or False
otherwise.
LRUD
True