문제
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;
}
'PS > 백준' 카테고리의 다른 글
[C++] 백준 25828: Corona Virus Testing (0) | 2023.05.22 |
---|---|
[C++] 백준 25881: Electric Bill (0) | 2023.05.21 |
[C++] 백준 25893: Majestic 10 (0) | 2023.05.19 |
[C++] 백준 27880: Gahui and Soongsil University statio (0) | 2023.05.18 |
[C++] 백준 22155: Простая задача (0) | 2023.05.17 |
댓글