-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[11650] 좌표 정렬하기
43 lines (38 loc) · 1.03 KB
/
[11650] 좌표 정렬하기
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
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
static int n,m;
static int[] arr;
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
HashMap <Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
int n = sc.nextInt();
for(int i=0; i<n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
if(map.containsKey(x)) {
list = map.get(x);
list.add(y);
Collections.sort(list);
}else {
list.add(y);
}
map.put(x, list);
}
for(int i=-100000; i<=100000; i++) {
if(map.containsKey(i)) {
for(int j=0; j<map.get(i).size(); j++) {
bw.write( i + " " + map.get(i).get(j) + "\n");
}
}
}
bw.flush();
}
}