-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay50.java
More file actions
74 lines (74 loc) · 1.56 KB
/
Copy pathDay50.java
File metadata and controls
74 lines (74 loc) · 1.56 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
i/p:
1 1 2 1 1 1
Output
3
i/p:
2 3 1 3 1 3 1 1 1 2
Output
1
i/p:
1 5 1 2 1 2 4 5 4 2
Output
0
i/p:
1 2 5 1 5 1 2 4 4 2
Output
3
*/
import java.util.*;
public class Day50{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
String strsplit[] = str.split(" ");
if (strsplit.length%2!=0) {
System.out.println("The length should be even");
}else{
int arr[] = new int[strsplit.length];
int temp[] = new int[strsplit.length];
int max = Integer.MIN_VALUE;
for (int i=0;i<strsplit.length ;i++ ) {
if (Integer.parseInt(strsplit[i])>max) {
max=Integer.parseInt(strsplit[i]);
}
}
boolean check = true;
int count=0;
for (int j=0;j<strsplit.length/2 ;j++ ) {
if (j==0) {
arr[0] = Integer.parseInt(strsplit[strsplit.length-1]);
for (int i=0;i<strsplit.length-1 ;i++ ) {
arr[i+1] = Integer.parseInt(strsplit[i]);
if (i>=(strsplit.length/2)) {
continue;
}else if (arr[i]>=max) {
check = false;
}
}
if (check) {
count++;
}
}else{
check = true;
arr[0] = temp[temp.length-1];
for (int i=0;i<temp.length-1 ;i++ ) {
arr[i+1] = temp[i];
if (i>=(temp.length/2)) {
continue;
}else if (arr[i]>=max) {
check = false;
}
}
if (check) {
count++;
}
}
for (int i=0;i<arr.length ;i++ ) {
temp[i] = arr[i];
}
}
System.out.println("Output\n"+count);
}
}
}