~cpp import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class JollyJumpers { int [] jumpersArray; int length; int differenceValue; boolean [] differenceArray; boolean jolly; // input()은 getIntArray()에서 사용 public String input() { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String input = ""; try { input = in.readLine(); } catch(IOException e) { e.printStackTrace(); } return input; } public int [] getIntArray() { String buf = input(); String [] stringArray = buf.split(" "); // 배열의 길이를 구한다(n) length = stringArray.length; int [] intArray = new int [length]; for(int i = 0; i < length; i++ ) { intArray[i] = Integer.parseInt(stringArray[i]); } return intArray; } public void inputJumpers() { // int형 배열을 얻는다 jumpersArray = getIntArray(); } public void checkDiffenceValue() { // 두 수의 차 값은 1 ~ n-1 differenceValue = length-1; // System.out.println(differenceValue); // checkDifferArray[] 를 초기화한다 differenceArray = new boolean [length]; differenceArray = setFalse( differenceArray ); int tempDiffer; for(int i = 0; i < differenceValue; i++) { tempDiffer = Math.abs( jumpersArray[i] - jumpersArray[i+1] ); // System.out.println(tempDiffer); if( tempDiffer < length) differenceArray[tempDiffer] = true; } } public boolean checkJolly() { jolly = true; for(int i = 1; i <= differenceValue; i++) { if ( differenceArray[i] == false ) { jolly = false; break; } } if(jolly) System.out.println("Jolly"); else System.out.println("Not Jolly"); return jolly; } public boolean [] setFalse( boolean [] temp ) { for(int i = 0; i < temp.length; i++) { temp[i] = false; } return temp; } public static void main(String args[]) { while(true) { JollyJumpers jj = new JollyJumpers(); jj.inputJumpers(); jj.checkDiffenceValue(); if(jj.jumpersArray[0] == 0) break; jj.checkJolly(); } } }