-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
56 lines (47 loc) · 1.61 KB
/
Main.java
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
package com.company;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.begin();
}
void begin() {
Scanner scan = new Scanner(System.in);
while(scan.hasNextLine()) {
String r = scan.nextLine();
StringTokenizer t = new StringTokenizer(r);
int num = Integer.parseInt(t.nextToken());
//System.out.println(num);
int [] values = new int[num];
for(int i = 0; i < num; i++) {
values[i] = Integer.parseInt(t.nextToken());
//System.out.println(values[i]);
}
int [] differences = new int[num - 1];
boolean jolly = false;
for(int i = 0; i < (num - 1); i++) {
differences[i] = Math.abs(values[i] - values[i+1]);
//System.out.println(differences[i]);
}
for(int i = 0; i < (num -1); i++) {
if (i != (num - 2)) {
if((differences[i] - differences[i+1]) == 1) {
jolly = true;
//System.out.println("Jolly True");
}
else {
jolly = false;
break;
}
}
}
if(jolly) {
System.out.print("Jolly\n");
}
else {
System.out.print("Not Jolly\n");
}
}
}
}