-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhorses.c
More file actions
39 lines (28 loc) · 706 Bytes
/
horses.c
File metadata and controls
39 lines (28 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
int compare( const void* a, const void* b ){
return *(int*)a-*(int*)b;
}
int main()
{
int N;
scanf("%d", &N);
int *horses= malloc(sizeof(int)* N);
for (int i = 0; i < N; i++) {
scanf("%d", &horses[i]);
}
int min=10000;
qsort(horses, N, sizeof(int), compare );
for (int i=1; i<N; i++){
int dif = abs(horses[i]-horses[i-1]);
dif<min?(min=dif):1;
}
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
printf("%d\n", min);
free(horses);
return 0;
}