文章
47
粉丝
109
获赞
8
访问
28.4k
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//1010 排序
int sort(const void* elem1, const void* elem2) {
return *(int*)elem1 - *(int*)elem2;
}
int main() {
int n = 0;
int s[1010] ;
int j[1010] = {0};//存放奇数
int o[1010] = {0};//存放偶数
int cnt_j = 0;//奇数个数
int cnt_o = 0;//偶数个数
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
for (int i = 0,l=0; i < n; i++) {
if (s[i] % 2 == 0) {
o[l] = s[i];
l++;
cnt_j++;
}
}
for (int i = 0,l = 0; i < n; i++) {
if (s[i] % 2 != 0) {
j[l] = s[i];
l++;
cnt_o++;
}
}
qsort(j,cnt_j,sizeof(s[0]),sort);
qsort(o, cnt_o, sizeof(s[0]), sort);
for (int i = 0; i < cnt_j; i++) {
printf("%d ", j[i]);
}
for (int i = 0; i < cnt_o; i++) {
printf("%d ", o[i]);
}
return 0;
}
第二种
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
int n;
scanf("%d", &a...
登录后发布评论
暂无评论,来抢沙发