# 18870: 좌표 압축

· May 15, 2022
Java
```import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

public class Main {

public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static MyScanner sc = new MyScanner();

static int pi(String s) {
return Integer.parseInt(s);
}

public static class MyScanner {
StringTokenizer st;

public MyScanner() {
}

String next() {
while (st == null || !st.hasMoreElements()) {
try {
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

long nextLong() {
return Long.parseLong(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

String nextLine() {
String str = "";
try {
} catch (IOException e) {
e.printStackTrace();
}
return str;
}

}
public static void main(String[] args) throws Exception {
int n = sc.nextInt();
int[] arr = new int[n];
int[] sorted = new int[n];
for(int i=0; i<n; i++){
arr[i] = sc.nextInt();
sorted[i] = arr[i];
}
Arrays.sort(sorted);
HashMap<Integer,Integer> hm = new HashMap<>();
int rank = 0;
int prev = sorted[0];
for(int i=0; i<n; i++){
if(prev!=sorted[i]){
rank++;
prev = sorted[i];
}
hm.put(sorted[i], rank);
}
for(int i=0; i<n; i++){
out.print(hm.get(arr[i])+" ");
}
out.flush();

}

}```
Output
`(Run the program to view its output)`