TopcoderArchiveVisit Topcoder
SRM29 Oct 2002
SRM 118

SpaceDrone

Problem statement, definition, constraints, and public examples.

Problem Statement

Our unmanned space vehicle responds to command sequences where each command is a single uppercase character that describes an action relative to the current location and orientation of the drone:
  • F -- move forward one unit
  • Y -- yaw 90 degrees counterclockwise as seen from the top of the drone
  • R -- roll 90 degrees counterclockwise as seen from the back of the drone
Y causes a rotation around the axis through the top and bottom of the drone. R causes a rotation around the axis through the back and front of the drone. Initially the drone is located at x=0,y=0,z=0. It is oriented so that its back-to-front axis is in the positive x direction, and its bottom to top axis is in the positive y direction. Create a class SpaceDrone that contains a method whereAmI that takes a command sequence as input and returns the x coordinate of the resulting position.

Definition

Class:
SpaceDrone
Method:
whereAmI
Parameters:
String
Returns:
int
Method signature:
int whereAmI(String commands)
(be sure your method is public)

Notes

  • Notice that the orientation of the xyz coordinate system is irrelevant since you only need to return the final x coordinate.

Constraints

  • commands contains between 1 and 50 characters inclusive
  • each character in commands is uppercase F, Y, or R

Examples

  1. "FFF"
    Returns: 3
    The drone goes forward along the x axis 3 units, ending at (3,0,0)
  2. "YYRRYRY""
    Returns: 0
    The drone has done multiple rotations, but has never moved from (0,0,0)
  3. "YFYFY"
    Returns: -1
  4. "YFRRYFFFY"
    Returns: 3
Back to all problems