평면에 n개의 점이 있다. 그중 두 개 이상의 점을 지나면서 x축 또는 y축에 평행한 직선이 몇 개인지 알아내는 프로그램을 작성하시오.
입력:
첫째 줄에 n(1 ≤ n ≤ 100,000)이 주어진다. 다음 n개의 줄에는 각 점의 좌표가 주어진다. 같은 좌표가 여러 번 주어질 수 있으며, 그런 경우 서로 다른 점으로 간주한다. 좌표는 절댓값이 231보다 작은 정수이다.
출력:
첫째 줄에 답을 출력한다.
입력:
4
0 0
10 10
0 10
10 0
출력:
4
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
Map<Integer, Integer> y = new HashMap<>(), x = new HashMap<>();
while (n-- > 0) {
st = new StringTokenizer(br.readLine());
int input = Integer.parseInt(st.nextToken());
if (y.containsKey(input))
y.put(input, y.get(input) + 1);
else
y.put(input, 0);
input = Integer.parseInt(st.nextToken());
if (x.containsKey(input))
x.put(input, x.get(input) + 1);
else
x.put(input, 0);
}
int cnt = 0;
for (int key : y.keySet())
if (y.get(key) > 0)
cnt++;
for (int key : x.keySet())
if (x.get(key) > 0)
cnt++;
bw.write(String.valueOf(cnt));
bw.flush();
}
}