Jin's Dev Story

[브론즈 3] 3009번 네 번째 점 본문

Coding Test/백준[JAVA]

[브론즈 3] 3009번 네 번째 점

woojin._. 2023. 8. 23. 10:50

문제 링크 : https://www.acmicpc.net/problem/3009

문제

세 점이 주어졌을 때, 축에 평행한 직사각형을 만들기 위해서 필요한 네 번째 점을 찾는 프로그램을 작성하시오.

입력

세 점의 좌표가 한 줄에 하나씩 주어진다. 좌표는 1보다 크거나 같고, 1000보다 작거나 같은 정수이다.

출력

직사각형의 네 번째 점의 좌표를 출력한다.

입력 1
5 5
5 7
7 5

출력 1
7 7

입력 2
30 20
10 10
10 20

출력 2
30 10

코드

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int x1=scan.nextInt();
		int y1=scan.nextInt();
		int x2=scan.nextInt();
		int y2=scan.nextInt();
		int x3=scan.nextInt();
		int y3=scan.nextInt();

		int x4 = (x1 == x2 ? x3 : (x1 == x3 ? x2 : x1));
		int y4 = (y1 == y2 ? y3 : (y1 == y3 ? y2 : y1));
		
		System.out.println(x4 + " " + y4);
	}

}