본문 바로가기
[ 다먹살 ]/- Coding

[백준] 9610 사분면

by 엉망으로살기 2022. 9. 23.
반응형

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

 

9610번: 사분면

2차원 좌표 상의 여러 점의 좌표 (x,y)가 주어졌을 때, 각 사분면과 축에 점이 몇 개 있는지 구하는 프로그램을 작성하시오.

www.acmicpc.net

 

또 오랜만에 푸는 간단한 문제이다. 대충 브론즈3 정도의 난이도라고 하며, 축인 케이스만 처리해주면 되는 단순 구현 문제였다.


문제 및 입출력 예제

 


코드

import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int[] cnt = new int[5];
        int n = sc.nextInt();
        String buf = sc.nextLine();
        
        for(int i=0; i<n; i++)
        {
            int x = sc.nextInt();
            int y = sc.nextInt();
            
            if(x==0 || y==0)
            {
                cnt[4]++;
            }
            else if(x>0)
            {
                if(y>0)
                {
                    cnt[0]++;
                }
                else
                {
                    cnt[3]++;
                }
            }
            else
            {
                if(y>0)
                {
                    cnt[1]++;
                }
                else
                {
                    cnt[2]++;
                }
            }
        }
        
        for(int i=0; i<5; i++)
        {
            if(i<4)
            {
                System.out.println("Q" + (i+1) + ": " + cnt[i]);
            }
            else
            {
                System.out.println("AXIS: " + cnt[4]);
            }
        }
        
        sc.close();
    }
}

반응형

'[ 다먹살 ] > - Coding' 카테고리의 다른 글

[백준] 2153 소수 단어  (0) 2022.09.29
[백준] 1357 뒤집힌 덧셈  (0) 2022.09.28
[백준] 25501 재귀의 귀재  (0) 2022.09.16
[백준] 2576 홀수  (0) 2022.07.19
[백준] 2441 별 찍기-4  (0) 2022.07.07

댓글