main
[백준-3009번/Java] 네 번째 점 본문
* x, y 좌표가 2개씩 같아야 함.
* HashMap 사용 - key값에 좌표 값, value 값이 빈도 수 입력
* 람다식 사용해서 HashMap foreach
import java.io.*;
import java.util.*;
public class Main {
public static class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Map<Integer, Integer> xMap = new HashMap<Integer, Integer>();
Map<Integer, Integer> yMap = new HashMap<Integer, Integer>();
for (int i = 0; i < 3; i++) {
StringTokenizer stk = new StringTokenizer(br.readLine(), " ");
int x = Integer.parseInt(stk.nextToken());
int y = Integer.parseInt(stk.nextToken());
if (xMap.containsKey(x)) {
xMap.put(x, xMap.get(x) + 1);
} else {
xMap.put(x, 1);
}
if (yMap.containsKey(y)) {
yMap.put(y, yMap.get(y) + 1);
} else {
yMap.put(y, 1);
}
}
Point p = new Point(0, 0);
xMap.forEach((key, value) -> {
if (value == 1) {
p.x = key;
}
});
yMap.forEach((key, value) -> {
if (value == 1) {
p.y = key;
}
});
System.out.println(p.x + " " + p.y);
}
}
728x90
'Algorithm' 카테고리의 다른 글
[백준-11650번/Java] 좌표 정렬하기 (0) | 2022.11.17 |
---|---|
[백준-1427번/Java] 소트인사이드 (0) | 2022.11.17 |
[백준-1934번/Java] 최소공배수 (0) | 2022.11.17 |
[백준-9012번/Java] 괄호 (0) | 2022.11.17 |
[백준-11047번/Java] 동전 0 (0) | 2022.11.17 |
Comments