반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

배움과 기록의 장

[백준] 3009번: 네 번째 점 (Java) 본문

problem solving

[백준] 3009번: 네 번째 점 (Java)

chaeunii 2023. 3. 25. 13:38

✅ 문제

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

 

✅ 풀이

  • x좌표부터 설명
    • x_coordinates라는 어레이리스트에 x좌표를 차례대로 넣는다.
    • 이 때, 이미 같은 값이 들어있다면 넣지않고, 이미 있는 값도 지워버린다.
    • 그럼 짝이 없는 x좌표 하나만 리스트에 남아있을 것이고, 이 값이 바로 우리가 출력해야할 네번째 점의 x좌표이다.
    • 네번째 점의 y좌표 구하는 것도 위와 마찬가지로 구하면 된다!
  •  

 

 

 

✅ 코드

import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        ArrayList<Integer> x_coordinates = new ArrayList<>();
        ArrayList<Integer> y_coordinates = new ArrayList<>();

        for(int i = 0; i < 3; i++){
            int x = sc.nextInt();
            int y = sc.nextInt();

            if(!x_coordinates.contains(x)) x_coordinates.add(x);
            else x_coordinates.remove((Integer) x);

            if(!y_coordinates.contains(y)) y_coordinates.add(y);
            else y_coordinates.remove((Integer) y);
        }

        System.out.println(x_coordinates.get(0) + " " + y_coordinates.get(0));

    }
}

 

반응형