Connection Status:
Competition Arena > SpaceDrone
SRM 118 · 2002-10-29 · by dgoodman
Class Name: SpaceDrone
Return Type: int
Method Name: whereAmI
Arg Types: (string)
Problem Statement

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.

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
0)
"FFF"
Returns: 3

The drone goes forward along the x axis 3 units, ending at (3,0,0)

1)
"YYRRYRY""
Returns: 0

The drone has done multiple rotations, but has never moved from (0,0,0)

2)
"YFYFY"
Returns: -1
3)
"RFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFYF"
Returns: 47
4)
"YFRFFYFFFRFFFFYFFFFF"
Returns: 5

Submissions are judged against all 23 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SpaceDrone with a public method int whereAmI(string commands) · 23 test cases · 2 s / 256 MB per case

Submitting as anonymous