JollyJumpers/권순의 (rev. 1.3)
Source Code ¶
import java.util.*;
public class JollyJumper {
public static void main(String[] args) {
int[] getNum = new int[3000];
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int num = sc.nextInt();
for (int i = 0; i < num; i++) {
getNum[i] = sc.nextInt();
}
if (isJolly(getNum, num))
System.out.println("Jolly");
else
System.out.println("Not jolly");
}
}
public static boolean isJolly(int[] array, int num){
int[] sub = new int[num - 1];
for (int i = 0; i < num - 1; i++) {
if (Math.abs(array[i + 1] - array[i]) > num - 1)
return false;
else
sub[i] = Math.abs(array[i + 1] - array[i]);
}
int count = 0;
int temp = 0;
while (count < num) {
for (int i = 0; i < num - 2; i++) {
if (sub[i + 1] < sub[i]) {
temp = sub[i];
sub[i] = sub[i + 1];
sub[i + 1] = temp;
}
}
count++;
}
for (int i = 0; i < num - 1; i++) {
if (sub[i] != (i + 1)) {
return false;
}
}
return true;
}
}
Source Code ¶
import java.util.*;
public class JollyJumper {
public static void main(String[] args) {
int[] getNum = new int[3000];
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int num = sc.nextInt();
for (int i = 0; i < num; i++) {
getNum[i] = sc.nextInt();
}
if (isJolly(getNum, num))
System.out.println("Jolly");
else
System.out.println("Not jolly");
}
}
public static boolean isJolly(int[] array, int num){
int[] sub = new int[num - 1];
for (int i = 0; i < num - 1; i++) {
if (Math.abs(array[i + 1] - array[i]) > num - 1)
return false;
else
sub[i] = Math.abs(array[i + 1] - array[i]);
}
int count = 0;
int temp = 0;
while (count < num) {
for (int i = 0; i < num - 2; i++) {
if (sub[i + 1] < sub[i]) {
temp = sub[i];
sub[i] = sub[i + 1];
sub[i + 1] = temp;
}
}
count++;
}
for (int i = 0; i < num - 1; i++) {
if (sub[i] != (i + 1)) {
return false;
}
}
return true;
}
}