- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_223.java
More file actions
Latest commit
35 lines (25 loc) · 733 Bytes
/
Copy pathTask_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
importjava.util.Scanner;
publicclassTask_223 {
publicstaticvoidmain(String[] args) {
Scanners = newScanner(System.in);
intn = s.nextInt();
int[] arr = newint[n];
intmax = 0;
for (inti = 0; i < n; i++) {
arr[i] = s.nextInt();
if (arr[i] > arr[max]) max = i;
}
intres = 0;
for(inti = 0; i < n - 1; i++) {
for (intj = n - 1; j > i; j--) {
if (arr[j - 1] > arr[j]) {
inttmp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = tmp;
res++;
}
}
}
System.out.print(res);
}
}