Skip to content

Commit 7792246

Browse files
authored
Create [17]_3.java
1 parent 410fdfe commit 7792246

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Solutions/[17]_3.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
3+
import java.util.Scanner;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
10+
int n = sc.nextInt();
11+
ArrayList<Integer> data = new ArrayList<Integer>();
12+
13+
for (int i = 0; i < n; i++) {
14+
data.add(sc.nextInt());
15+
}
16+
17+
// 오름차순 정렬 수행
18+
Collections.sort(data);
19+
20+
// 불만도의 합 계산
21+
long result = 0;
22+
for (int i = 1; i <= n; i++) {
23+
result += Math.abs(i - data.get(i - 1));
24+
}
25+
26+
System.out.println(result);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)