본문 바로가기
  • Let's study
PS/백준

[C++] 백준 9772: Quadrants

by 코딩고수이고파 2023. 5. 20.

문제

https://www.acmicpc.net/problem/9772

 

9772번: Quadrants

Given the coordinates (x,y) of some points in 2-dimensional plane, find out which quadrant(Q1-Q4) the points are located. If a point is located on X-axis or Y-axis, print out AXIS instead.

www.acmicpc.net

 

해결방법

x와 y가 양수인지 음수인지로 어느 사분면인지 출력하고 축이면 AXIS를 출력한다. 마지막 0 0일 때도 AXIS를 출력해야 한다.

 

코드

#include<iostream>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	double x, y;
	while (cin >> x >> y) {
		if (x > 0 && y > 0)
			cout << "Q1\n";
		else if (x > 0 && y < 0)
			cout << "Q4\n";
		else if (x < 0 && y>0)
			cout << "Q2\n";
		else if (x < 0 && y < 0)
			cout << "Q3\n";
		else
			cout << "AXIS\n";

		if (x == 0 && y == 0) {
			break;
		}
	}

	return 0;
}

댓글