-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdin.c
47 lines (45 loc) · 1.04 KB
/
stdin.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define maxn 100
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main() {
int A[maxn];
int i = 0, temp = 0, data = 0, capacity = 0, count = 0;
memset(A, 0, sizeof(A));
while (1){
if (scanf("%d", &data) == 1) {
if ((temp = getchar()) != '\n') {
A[i] = data;
i++;
capacity++;
} else {
A[i] = data;
i++;
capacity++;
break;
}
}
}
qsort(A, capacity, sizeof(int), compare);
for (i = 0; i < capacity; i++) {
if(A[i] % 2 != 0) {
printf("%d", A[i]);
count++;
if (count != capacity)
printf(",");
}
}
for (i = 0; i < capacity; i++) {
if(A[i] % 2 == 0) {
printf("%d", A[i]);
count++;
if (count != capacity)
printf(",");
}
}
return 0;
}