U E D R , A S I H C RSS

Jolly Jumpers/권순의

Difference between r1.3 and the current

@@ -60,62 +60,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;
}
}
 
}}}



Status

Memory5272KTime579MS

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;
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:34
Processing time 0.0321 sec