-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoj18870.java
More file actions
34 lines (29 loc) · 757 Bytes
/
Boj18870.java
File metadata and controls
34 lines (29 loc) · 757 Bytes
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
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
public class Boj18870 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] origin = new int[N];
int[] sorted = new int[N];
for(int i=0; i<N;i++) {
origin[i] = sorted[i] = sc.nextInt();
}
Arrays.sort(sorted);
HashMap<Integer, Integer> ranking = new HashMap<>();
int rank = 0;
for(int v: sorted) {
if(!ranking.containsKey(v)) {//v라는 key값이 Map 안에 없다면
ranking.put(v, rank);
rank++;
}
}
StringBuilder sb= new StringBuilder();
for(int v:origin) {
int res = ranking.get(v);
sb.append(res).append(" ");
}
System.out.println(sb);
}//main
}//class