CodingTest/UVa
[Java] 유쾌한 점퍼 Jolly Jumper
슬라임 통통
2020. 9. 9. 00:16
728x90
[Java] 유쾌한 점퍼 Jolly Jumper
문제 설명
내 코드
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.lang.Math;
class Main {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextInt()){
int n = scanner.nextInt();
int input []= new int[n];
int output[] = new int[n-1];
for (int i =0; i< n; i++){
input[i] = scanner.nextInt();
if(i>0)
output[i-1]= Math.abs(input[i]-input[i-1]);
}
Arrays.sort(output);
String jollystr ="Jolly";
for(int i=0; i < n-1; i++){
if( output[i] != i+1 )
jollystr = "Not jolly";
}
System.out.println(jollystr);
}
}
}
🔑 Key Point 🔑
import java.lang.Math;
Math.abs(-6); //6이 나옴
import java.util.Arrays;
int [] arr= {1,3,2};
Arrays.sort(arr); //arr 가 {1,2,3}이 됨
절댓값 함수와 배열 sort 함수 알아두기!
728x90
반응형