#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int compare(const void* a, const void* b, const int is_descending);
void print_array(int* array);
int main(void)
{
int input;
int i = 0, j = 0, length = 0;
int arr[100], answer[100];
while (scanf("%d", &input) != EOF)
{
arr[length] = input;
length += 1;
}
arr[length] = EOF;
answer[length] = EOF;
qsort(arr, length, sizeof(arr[0]), compare, 0);
int odd_idx = 0, even_idx = length - 2;
for (i = 0; i < length; i++)
{
if (arr[i] % 2 != 0)
{
answer[odd_idx] = arr[i];
odd_idx += 2;
}
else
{
answer[even_idx] = arr[i];
even_idx -= 2;
}
}
while (answer[j] != EOF)
{
printf("%d ", answer[j]);
j += 1;
}
return 0;
}
int compare(const void* a, const void* b, const int is_descending)
{
int out;
if (*(int*)a < *(int*)b)
{
out = (is_descending == 0) ? -1 : 1;
}
else if (*(int*)a > *(int*)b)
{
out = (is_descending == 0) ? 1 : -1;
}
else
{
out = 0;
}
return out;
}
2021年11月30日 16:16
풀이 작성
코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.