-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathp399.c
56 lines (53 loc) · 1.43 KB
/
p399.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Las perlas de la condesa */
#include <stdio.h>
#include <stdlib.h>
int comp (const void * elem1, const void * elem2)
{
int f = *((int*)elem1);
int s = *((int*)elem2);
if (f < s) return -1;
if (f > s) return 1;
return 0;
}
int main() {
long long input[1000], output[1000];
int len, res;
int i, j, k;
while(1) {
scanf("%lld", &input[0]);
if(input[0] == 0)
return 0;
len = 1;
for(i = 1; ; i++) {
scanf("%lld", &input[i]);
if(input[i] == 0)
break;
len++;
}
if(len % 2) {
qsort(input, len, sizeof(long long), comp);
res = 1;
for(i = 0, j = 0, k = len-1; i < len; i = i + 2) {
if(input[i] == input[i+1] && i < len-1) {
output[j] = input[i]; j++;
output[k] = input[i]; k--;
} else if(i == len-1) {
output[j] = input[i];
} else {
res = 0;
}
}
if(res) {
for(i = 0; i < len; i++) {
if(i == 0)
printf("%lld", output[i]);
else
printf(" %lld", output[i]);
}
printf("\n");
} else
printf("NO\n");
} else
printf("NO\n");
}
}