SpaceDrone
SRM 118 · 2002-10-29 · by dgoodman
SRM 118 · 2002-10-29 · by dgoodman
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
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