-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_223.java
More file actions
35 lines (25 loc) · 733 Bytes
/
Task_223.java
File metadata and controls
35 lines (25 loc) · 733 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
35
import java.util.Scanner;
public class Task_223 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
int max = 0;
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
if (arr[i] > arr[max]) max = i;
}
int res = 0;
for(int i = 0; i < n - 1; i++) {
for (int j = n - 1; j > i; j--) {
if (arr[j - 1] > arr[j]) {
int tmp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = tmp;
res++;
}
}
}
System.out.print(res);
}
}