Problem J
Starfox Coordinates
![\includegraphics[width=0.3\textwidth ]{arwing_sm.jpg}](/problems/starfoxcoordinates/file/statement/en/img-0001.jpg)
Fox McCloud has left the Lylat System and is headed for our galaxy, the Milky Way, to protect us from intergalactic threats.1 He needs your computing expertise to be able to navigate safely and quickly in this new terrain.
His Arwing starfighter has been updated to use the Galactic Coordinate System that describes the location of objects in the Milky Way Galaxy.
It’ll be your job to write a program that verifies a given coordinate string is valid. The fate of our galaxy rests in your hands!!
Galactic Coordinate System
A galactic coordinate describes an object’s galactic latitude and galactic longitude. Both of these use the following units:
-
degrees $[-360, +360]$ ($1-3$ digits)
-
minutes $[00, 59]$ (always $2$ digits)
-
seconds $[00, 59]$ (always $2$ digits)
Using the following format (e.g. $0$ degrees, $10$ minutes, $7$ seconds)
On top of this, the latitude and longitude have limits on how large or small they can be.
Galactic latitude (b) must be in the interval
-90*00'00" $\leq b \leq $ +90*00'00"
Galactic longitude (l) must be in the interval
+0*00'00" $\leq l \leq $ +360*00'00"
A valid coordinate string contains the galactic latitude followed by the galactic longitude, separated by a single space.
Examples
correct
+0*07'12" +10*04'06"
incorrect
+0*05'01" # Missing the longitude 15*07'37" 37*08'00" # Missing sign -10*63'65" +32*85'89" # Minutes and seconds out of range starfoxiscool -10*60'00" +0*30'30" # extra characters -90*01'01" +360*00'01" # Out of range on both
Input
As input you will be given a string representing the coordinate string that you will verify. You will need to check the formatting as well as make sure the coordinates are valid values. The input will never contain leading or trailing whitespace and will never contain newline characters.
Each input is a string with length $N$ $(0 \leq N \leq 100)$. There will be no leading or trailing whitespace and no newlines.
Output
Print True if the string is a valid coordinate, False otherwise.
Sample Input 1 | Sample Output 1 |
---|---|
+0*40'37" +80*00'17" |
True |
Sample Input 2 | Sample Output 2 |
---|---|
0*40'37" 80*00'17" |
False |
Sample Input 3 | Sample Output 3 |
---|---|
hands off my bread |
False |
Footnotes
- Star Fox, associated characters, and above image © Nintendo Co., Ltd. Used here for educational purposes only, in accordance with fair use as defined by section 107 of the Copyright Act.