125. Jolly Jumpers

 avatar
user_6817964
c_cpp
2 years ago
1.0 kB
1
Indexable
Never
#include <stdio.h> // printf

void Jolly_Jumpers(int Array[], int size);

void Jolly_Jumpers(int Array[], int size) {
    int sum[100];
    for (int i = 0; i < size - 1; i++) {
        sum[i] = (Array[i] - Array[i + 1] > 0) ? (Array[i] - Array[i + 1]) : (Array[i + 1] - Array[i]);
    }

    for (int i = 0; i < size - 1; i++) {
        for (int j = i + 1; j < size - 1; j++) {
            if (sum[i] > sum[j]) {
                int temp = sum[i];
                sum[i] = sum[j];
                sum[j] = temp;
            }
        }

    }

    int flag = 1;

    for (int i = 0; i < size - 1; i++) {
        if (sum[i] != i + 1) {
            flag = 0;
            break;
        }
    }

    if (flag == 1)
        printf("Jolly");
    else
        printf("Not jolly");

}

int main() {
    int size;
    scanf_s("%d", &size);

    int Array[100], i;
    for (i = 0; i < size; i++) {
        scanf_s("%d", &Array[i]);
    }

    Jolly_Jumpers(Array, size);
    return 0;
}