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

Point Quadrant

Find which quadrant a point lies in.

배우게 될 내용

  • Check the signs of x and y
  • Handle points on the axes
  • Combine two conditions

문제

번역본 보기

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

예시

예시 1
입력:
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.

예시 2
입력:
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

First determine whether the point lies on an axis or at the origin.

힌트 2

If it is not on an axis, the signs of x and y tell you the quadrant.

힌트 3

The origin is a special case, and axis points are not in any quadrant.

예상 복잡도

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

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.

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

# 코더 언어 시간 메모리 AI 평가 풀이
1 ДЗДавид Зайдулин Python 968 ms - 5/5 코드 보기
2 HJhettory Jurash Python 976 ms - 2/5 코드 보기
3 LMLaura Mahlow Python 1,003 ms - 5/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 풀이

스포일러: 아래에 전체 풀이 3개가 있습니다 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.