Title Description:
Enter an array of integers to implement a function that adjusts the order of the numbers in the array so that all the odd digits are placed in the first half of the array, all the even digits are located in the second half of the array, and the relative positions between the odd and odd, even and even, are guaranteed.
Input:
Each input file contains a set of test cases.
For each test case, enter an n for the first row, representing the number of digits in the array.
Enter n integers for the next line. Represents the number of n in an array.
Output:
corresponding to each test case,
Enter a row of n digits, representing the adjusted array. Note that the numbers and numbers are separated by a space, and there are no spaces after the last number.
Sample Input:
5
1 2 3 4 5
Sample output:
1 3 5) 2 4
AC Code:
#include <stdio.h> #include <stdlib.h> int main () {int i, n;
while (scanf ("%d", &n)! = EOF) {int *a = (int *) malloc (sizeof (int) *n);
int *odd = (int *) malloc (sizeof (int) *n);
int *even = (int *) malloc (sizeof (int) *n);
int oindex = 0, eindex = 0;
for (i = 0; i < n; i++) {scanf ("%d", &a[i]);
If (A[i]% 2) {odd[oindex++] = A[i];
} else {even[eindex++] = A[i];
}} for (i = 0; i < Oindex; i++) {if (i! = n-1) {printf ("%d", odd[i]);
} else {printf ("%d", odd[i]); }} for (i = 0; i < Eindex; i++) {if (i! = eIndex-1) {printf ("%d", Even[i]
);
} else {printf ("%d", even[i]);
}} printf ("\ n");
Free (a); A =NULL;
Free (odd);
Odd = NULL;
Free (even);
even = NULL;
} return 0;
}/************************************************************** problem:1516 User:wusuopubupt language:c
result:accepted time:70 Ms memory:2088 KB ****************************************************************/