-
Notifications
You must be signed in to change notification settings - Fork 3
/
1259.c
85 lines (66 loc) · 1.24 KB
/
1259.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//1259 - Pares e Ímpares
//https://www.urionlinejudge.com.br/judge/pt/problems/view/1259
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compara(const void *p1, const void *p2)
{ int *i = (int *)p1, *j = (int *)p2;
if (*i > *j)
return 1;
else
if (*i == *j)
return 0;
else
return -1;
}
int compara2(const void *p1, const void *p2)
{ int *i = (int *)p1, *j = (int *)p2;
if (*i < *j)
return 1;
else
if (*i == *j)
return 0;
else
return -1;
}
int main ()
{
int N, c = 0, aux, d = 0, cont = 0, con = 0, tamPar = 0, tamFinal = 0, tamImpar = 0;
scanf("%d", &N);
int vPar[N], vImpar[N], vFinal[N];
do
{
scanf("%d", &aux);
if(aux%2 == 0) {
vPar[c] = aux;
c++;
}
else {
vImpar[d] = aux;
d++;
}
cont++;
} while(cont<N);
tamPar = c;
tamImpar = d;
qsort(vPar, tamPar, sizeof(int), compara);
qsort(vImpar, tamImpar, sizeof(int), compara2);
aux = 0;
c = 0;
d = 0;
for(aux=0;aux<N;aux++)
{
for(c=0;c<tamPar;c++){
vFinal[aux] = vPar[c];
aux++;
}
for(d=0;d<tamImpar;d++){
vFinal[aux] = vImpar[d];
aux++;
}
}
for(aux=0;aux<N;aux++)
printf("%d\n", vFinal[aux]);
return 0;
}