समस्या
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
पहले तय करो कि point axis पर है या origin पर.
संकेत 2
अगर axis पर नहीं है, तो x और y के signs से quadrant पता चलता है.
संकेत 3
Origin एक special case है, और axis points किसी quadrant में नहीं होते.
अपेक्षित जटिलता
समय O(1), अतिरिक्त स्थान O(1)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।