https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=979 困難度 ★ 這題的意思是一個串列中每個差排序後是有順序的 例如4個數字所有的差為1~(n-1)=>1 4 2 3 差為 3 2 1=>1 2 5 7 差為 1 3 2 所以解法是先紀錄串列的差然後再做排序最後再做驗證是否為1~(n-1)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
int n = scn.nextInt(), arr[] = new int[n - 1], a, b = 0, j;
for (int i = 0; i < n; i++) {
a = scn.nextInt();
if (i > 0)
arr[i - 1] = Math.abs(a - b);
b = a;
}
Arrays.sort(arr);
for (j = 0; j < arr.length; j++) {
if (arr[j] != j + 1)
break;
}
if (j == n - 1)
System.out.println("Jolly");
else
System.out.println("Not jolly");
}
}
/*
題目:Q10038 : Jolly Jumpers
作者:1010
時間:西元 2016 年 5 月 */
}