-
Notifications
You must be signed in to change notification settings - Fork 0
/
18870(HashMap).java
41 lines (32 loc) · 1.05 KB
/
18870(HashMap).java
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
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));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int N = Integer.parseInt(br.readLine());
int arr[] = new int[N];
int sort[] = new int[N];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++){
int temp = Integer.parseInt(st.nextToken());
arr[i] = temp;
sort[i] = temp;
}
Arrays.sort(sort);
HashMap<Integer, Integer> hashMap = new HashMap<>();
int current = 0;
hashMap.put(sort[0], current);
for(int i = 1; i < N; i++){
if(sort[i] != sort[i - 1]){
current++;
hashMap.put(sort[i], current);
}
}
for(int i = 0; i < N; i++){
sb.append(hashMap.get(arr[i])).append(" ");
}
System.out.println(sb);
}
}