洛谷——P1152欢乐的跳

Posted on 2024-03-17 19:24  奇诺qwq  阅读(20)  评论(0编辑  收藏  举报

 

 思路

1、接收数据

2、abs得出相邻两数差的绝对值,存入数组

3、用f=true,记录是否满足条件

4、对数组进行排序后,判断是否等于[1,n-1]间的数,有一个不是就跳出循环

 

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int n =sc.nextInt();
        int[] arr = new int[n];
        int[] a1 = new int[n-1];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        for (int i = 0; i < n-1; i++) {
            a1[i] = Math.abs(arr[i+1]-arr[i]);
        }
        Arrays.sort(a1);
        boolean f = true;
        for (int i = 0; i < n-1; i++) {
            if (a1[i] != i + 1) {
                f = false;
                break;
            }
        }
        if(f) System.out.println("Jolly");
        else System.out.println("Not jolly");
    }
}