/*
プログラミングのお題スレ Part5
https://m...content-available-to-author-only...h.net/test/read.cgi/tech/1564310397/
832デフォルトの名無しさん2019/10/23(水) 20:25:56.13ID:LcbXQT4h>>833>>836>>837>>838>>839>>842
お題:整数配列の奇数要素のみをソートした配列を返す処理を書いてください
入力例:[6, 5, 4, 3, 2, 1]
出力例:[6, 1, 4, 3, 2, 5]
858デフォルトの名無しさん2019/10/26(土) 07:11:59.41ID:I0XoRu/q>>859>>861>>866
お題:>>832 に「偶数要素は2で割って降順ソート」という要件を追加してください
すでに回答済みの場合は最少限の変更でのご対応で腕(もしくは言語のポテンシャル)を見せてください
859デフォルトの名無しさん2019/10/26(土) 07:27:04.95ID:I0XoRu/q>>862
>>858
入力例:[0, 9, 8, 4, 6, 5, 1, 2, 7, 3]
出力例:[4, 1, 3, 2, 1, 3, 5, 0, 7, 9]
*/
#include <stdio.h>
#define ARRSIZE(arr) (sizeof(arr)/sizeof(arr[0]))
void show(int arr[], int size){
int i;
for(i = 1; i < size; i++)
}
void swap(int *a, int *b){
int t = *a; *a = *b; *b = t;
}
void sort(int arr[], int size){
int *p,*q,*e = arr + size;
for(p = arr; p < e; p++){
for(q = p+1; q < e; q++)
if(*p%2 && *q%2 && *p>*q || !(*p%2) && !(*q%2) && *p<*q)
swap(p,q);
if(!(*p%2))
*p /= 2;
}
}
int main(void){
int arr[] = {0, 9, 8, 4, 6, 5, 1, 2, 7, 3};
int size = ARRSIZE(arr);
show(arr, size);
sort(arr, size);
show(arr, size);
return 0;
}
LyoKICDjg5fjg63jgrDjg6njg5/jg7PjgrDjga7jgYrpoYzjgrnjg6wgUGFydDUKICBodHRwczovL20uLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmgubmV0L3Rlc3QvcmVhZC5jZ2kvdGVjaC8xNTY0MzEwMzk3LwoKICA4MzLjg4fjg5Xjgqnjg6vjg4jjga7lkI3nhKHjgZfjgZXjgpMyMDE5LzEwLzIzKOawtCkgMjA6MjU6NTYuMTN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