U E D R , A S I H C RSS

Jolly Jumpers/강소현

Difference between r1.3 and the current

@@ -1,10 +1,11 @@
== Status ==
||Problem|| 2575||User||talin0528||
||Memory||5224K||Time||360MS||
||Language||Java||Result||Accepted||
== Source Code ==
{{{
import java.util.Scanner;
public class JollyJumpers{
public class Main{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);


Status

Problem 2575Usertalin0528
Memory5224KTime360MS
LanguageJavaResultAccepted

Source Code

import java.util.Scanner;
public class Main{
	public static void main(String [] args)
	{
		Scanner scan = new Scanner(System.in);
		int[] arr = new int[3000];	
		while(scan.hasNextInt()){
			int size = scan.nextInt();
			int i;
			for(i=0; i<size; i++){
				arr[i] = scan.nextInt();
			}
			if(isJolly(arr, size)){		//졸리점퍼 체크
				System.out.println("Jolly");
			}else{
				System.out.println("Not jolly");
			}
		}
	}
	
	public static boolean isJolly(int [] arr, int size){
		int [] jollyNum = new int [size];
		for(int i=0; i<size-1; i++){
			if(Math.abs(arr[i+1]-arr[i]) >= size)//size 넘어가면 1~n-1을 넘어가니까.
				return false;
			else
				jollyNum[Math.abs(arr[i+1]-arr[i])]++;
		}
		for(int i=1; i<=size-1;i++){
			if(jollyNum[i] == 0)//1~n-1 중 하나라도 포함 안하면 not jolly
				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