建两个数组就好了,一个存奇数一个存偶数,然后sort一下,最后输出。
#include <iostream>
#include <algorithm>
using namespace std;
bool comp(int left,int right){
if(left > right) return true;
return false;
}
int main(){
int A[10]={-1};
int B[10]={-1};
int i = 0 ,j = 0 , y = 0 , n = 0 ;
while(cin >> y){
if(i==10) i=0;
if(j==10) j=0;
if( y % 2 == 0 ){
A[i++] = y ;
}else{
B[j++] = y ;
}
n++;
if(n==10){
n=0;
sort(A,&A[i]);
sort(B,&B[j],comp);
for(int x = 0 ; x < j ; x++){
cout << B[x] << ' ';
}
for(int x = 0 ; x < i ; x++){
cout << A[x] << ' ';
}
cout << '\n' ;
}
}
return 0;
}
结果如下: