문제
The x and y axes split the plane into four quadrants: Q1 (x > 0, y > 0), Q2 (x < 0, y > 0), Q3 (x < 0, y < 0) and Q4 (x > 0, y < 0). Points on an axis belong to no quadrant.
Implement point_quadrant(x, y).
Input
x: The x coordinate. y: The y coordinate.
Output
Return "Q1", "Q2", "Q3" or "Q4"; "X-axis" or "Y-axis" for points on an axis; or "Origin" for (0, 0).
제약 조건
-1,000,000 ≤ x, y ≤ 1,000,000
예시
입력:
x = -3
y = 4
예상 출력:
expected = "Q2"
입력:
long long x = -3;
long long y = 4;
예상 출력:
std::string expected = "Q2";
입력:
long x = -3;
long y = 4;
예상 출력:
string expected = "Q2";
설명
x is negative and y is positive, so the point is in Q2.
입력:
x = 5
y = 0
예상 출력:
expected = "X-axis"
입력:
long long x = 5;
long long y = 0;
예상 출력:
std::string expected = "X-axis";
입력:
long x = 5;
long y = 0;
예상 출력:
string expected = "X-axis";
설명
y is 0, so the point lies on the X-axis.
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
먼저 점이 축 위인지, 원점인지 판단하세요.
힌트 2
축 위가 아니라면 x와 y의 부호로 사분면을 알 수 있습니다.
힌트 3
원점은 특별한 경우이고, 축 위의 점은 어느 사분면에도 속하지 않습니다.
예상 복잡도
시간 O(1), 추가 공간 O(1)
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.