Problem
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).
Einschränkungen
-1,000,000 ≤ x, y ≤ 1,000,000
Beispiele
Eingabe:
x = -3
y = 4
Erwartete Ausgabe:
expected = "Q2"
Eingabe:
long long x = -3;
long long y = 4;
Erwartete Ausgabe:
std::string expected = "Q2";
Eingabe:
long x = -3;
long y = 4;
Erwartete Ausgabe:
string expected = "Q2";
Erläuterung
x is negative and y is positive, so the point is in Q2.
Eingabe:
x = 5
y = 0
Erwartete Ausgabe:
expected = "X-axis"
Eingabe:
long long x = 5;
long long y = 0;
Erwartete Ausgabe:
std::string expected = "X-axis";
Eingabe:
long x = 5;
long y = 0;
Erwartete Ausgabe:
string expected = "X-axis";
Erläuterung
y is 0, so the point lies on the X-axis.
So gehst du vor
Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.
Hinweis 1
Bestimme zuerst, ob der Punkt auf einer Achse oder im Ursprung liegt.
Hinweis 2
Wenn er nicht auf einer Achse liegt, sagen die Vorzeichen von x und y dir das Quadrant.
Hinweis 3
Der Ursprung ist ein Sonderfall, und Punkte auf den Achsen liegen in keinem Quadranten.
Erwartete Komplexität
Zeit O(1), zusätzlicher Speicher O(1)
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.