문제 링크: https://www.acmicpc.net/problem/14681
백준 조건문 4단계 - 14681번 사분면 고르기를 풀어보았다.
풀이: 좌표를 받아 어느 사분면에 있는지 출력하면 된다.
C++
#include <iostream>
using namespace std;
int main() {
int x,y;
cin >> x;
cin >> y;
if(x>0&&y>0)
{
cout<<1;
}
if(x<0&&y>0)
{
cout<<2;
}
if(x<0&&y<0)
{
cout<<3;
}
if(x>0&&y<0)
{
cout<<4;
}
}
Python
x=int(input())
y=int(input())
if(x>0 and y>0): print(1)
if(x<0 and y>0): print(2)
if(x<0 and y<0): print(3)
if(x>0 and y<0): print(4)
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
if(a>0&&b>0) System.out.println(1);
if(a<0&&b>0) System.out.println(2);
if(a<0&&b<0) System.out.println(3);
if(a>0&&b<0) System.out.println(4);
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
오븐 시계 풀이 (0) | 2022.12.30 |
---|---|
알람 시계 풀이 (0) | 2022.12.30 |
윤년 풀이 (0) | 2022.12.30 |
시험 성적 풀이 (0) | 2022.12.30 |
두 수 비교하기 풀이 (0) | 2022.12.30 |