Problema
US interstate numbers follow a pattern. Numbers 1 to 99 are primary routes: odd numbers run north-south and even numbers run east-west. Three-digit numbers are auxiliary routes (loops and spurs) that serve the primary route given by their last two digits, so I-405 serves I-5 and I-290 serves I-90. An auxiliary route runs in the same direction as the route it serves. A three-digit number ending in 00 does not serve any route and is not valid, and neither is 0 or anything above 999.
Implement interstate_highway_numbers(number).
Input
number: The highway number.
Output
Return one of these strings, where D is north-south or east-west and P is the served primary route:
"Primary route, runs D"for 1 to 99"Auxiliary route of I-P, runs D"for valid numbers from 101 to 999"Invalid"for everything else
Restricciones
−10,000 ≤ number ≤ 10,000
Ejemplos
Entrada:
number = 95
Salida esperada:
expected = "Primary route, runs north-south"
Entrada:
long long number = 95;
Salida esperada:
std::string expected = "Primary route, runs north-south";
Entrada:
long number = 95;
Salida esperada:
string expected = "Primary route, runs north-south";
Explicación
95 is odd and below 100, so the answer is "Primary route, runs north-south".
Entrada:
number = 290
Salida esperada:
expected = "Auxiliary route of I-90, runs east-west"
Entrada:
long long number = 290;
Salida esperada:
std::string expected = "Auxiliary route of I-90, runs east-west";
Entrada:
long number = 290;
Salida esperada:
string expected = "Auxiliary route of I-90, runs east-west";
Explicación
The last two digits are 90, an even primary route, so the answer is "Auxiliary route of I-90, runs east-west".
Cómo abordarlo
Inténtalo primero por tu cuenta y luego abre las pistas una a una.
Pista 1
Rule out 0, negatives, numbers above 999 and multiples of 100 first.
Pista 2
number % 100 gives the primary route a three-digit number serves.
Pista 3
The direction depends on whether that primary route number is odd or even.
Complejidad esperada
O(1) time, O(1) extra space
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.