반응형
1.Scanner를 이용한 방법
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] a = {sc.nextInt(), sc.nextInt()};
int[] b = {sc.nextInt(), sc.nextInt()};
int[] c = {sc.nextInt(), sc.nextInt()};
int x = 0;
int y = 0;
//x좌표 비교
if(a[0] == b[0]){
x = c[0];
}else if(a[0] == c[0]){
x = b[0];
}else{
x = a[0];
}
//y좌표 비교
if(a[1] == b[1]){
y = c[1];
}else if(a[1] == c[1]){
y = b[1];
}else{
y = a[1];
}
System.out.println(x + " " + y);
sc.close();
}
}
2. BufferedReader를 이용한 방법
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine(), " ");
int[] a = {Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())};
st = new StringTokenizer(br.readLine(), " ");
int[] b = {Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())};
st = new StringTokenizer(br.readLine(), " ");
int[] c = {Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())};
int x = 0;
int y = 0;
//x좌표 비교
if(a[0] == b[0]){
x = c[0];
}else if(a[0] == c[0]){
x = b[0];
}else{
x = a[0];
}
//y좌표 비교
if(a[1] == b[1]){
y = c[1];
}else if(a[1] == c[1]){
y = b[1];
}else{
y = a[1];
}
System.out.println(x + " " + y);
br.close();
}
}
StringTokenizer는 한 번 쓰면 또 선언해줘야하는 게 아쉽다...
반응형
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 9063 - 대지 (JAVA/ 자바) (0) | 2024.04.14 |
---|---|
[백준] 15894 - 수학은 체육과목 입니다. (JAVA/ 자바) (0) | 2024.04.13 |
[백준] 1085 - 직사각형에서 탈출 (JAVA/ 자바) (0) | 2024.04.11 |
[백준] 27323 - 직사각형 (JAVA/ 자바) (0) | 2024.04.10 |
[백준] 11653 - 소인수분해 (JAVA/ 자바) (0) | 2024.04.09 |