모든 챌린지
쉬움 0명 해결 정답률 0%

Interstate Highway Numbers

Classify an interstate highway number as a primary or auxiliary route and give its direction.

배우게 될 내용

  • Use % to find the last two digits and parity
  • Separate valid from invalid inputs
  • Build result strings from parts

문제

번역본 보기

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

제약 조건

−10,000 ≤ number ≤ 10,000

예시

예시 1
입력:
number = 95

예상 출력:
expected = "Primary route, runs north-south"
입력:
long long number = 95;

예상 출력:
std::string expected = "Primary route, runs north-south";
입력:
long number = 95;

예상 출력:
string expected = "Primary route, runs north-south";

설명

95 is odd and below 100, so the answer is "Primary route, runs north-south".

예시 2
입력:
number = 290

예상 출력:
expected = "Auxiliary route of I-90, runs east-west"
입력:
long long number = 290;

예상 출력:
std::string expected = "Auxiliary route of I-90, runs east-west";
입력:
long number = 290;

예상 출력:
string expected = "Auxiliary route of I-90, runs east-west";

설명

The last two digits are 90, an even primary route, so the answer is "Auxiliary route of I-90, runs east-west".

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Rule out 0, negatives, numbers above 999 and multiples of 100 first.

힌트 2

number % 100 gives the primary route a three-digit number serves.

힌트 3

The direction depends on whether that primary route number is odd or even.

예상 복잡도

O(1) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

아직 통과한 풀이가 없습니다. 풀어서 1위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.