-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_18870.java
More file actions
51 lines (46 loc) ยท 1.18 KB
/
_18870.java
File metadata and controls
51 lines (46 loc) ยท 1.18 KB
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
44
45
46
47
48
49
50
51
package backjoon;
// https://www.acmicpc.net/problem/18870
// ์ขํ ์์ถ
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class _18870 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// memory 359492 runtime 1696
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int[] nums = new int[N];
for (int i = 0; i < N; i++){
nums[i] = Integer.parseInt(st.nextToken());
}
// ์ ๋ ฌ
int[] sortNums = nums.clone();
Arrays.sort(sortNums);
// ์ค๋ณต๋์ง ์๋ ์ขํ๊ฐ๊ณผ idx์ ์ฅ
Map<Integer, Integer> map = new HashMap<>();
int idx = 0;
for(int n : sortNums){
if(!map.containsKey(n)){
map.put(n, idx++);
}
}
// ์ถ๋ ฅ
StringBuffer sb = new StringBuffer();
for(int n : nums){
sb.append(map.get(n)).append(" ");
}
System.out.println(sb);
}
}
/*
input
5
2 4 -10 4 -9
output
2 3 0 3 1
*/