給定10個整數的序列,要求對其從新排序。排序要求:ios
1.奇數在前,偶數在後;spa
2.奇數按從大到小排序;code
3.偶數按從小到大排序。blog
4 7 3 13 11 12 0 47 34 98
47 13 11 7 3 0 4 12 34 98
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 int main() 5 { 6 int a[10],b[10],c[10],m=0,n=0; 7 for (int i=0;i<10;++i) 8 { 9 cin >> a[i]; 10 if (a[i]%2==1) 11 { 12 b[m++] =a[i]; 13 } 14 else 15 { 16 c[n++] = a[i]; 17 } 18 } 19 sort(b, b + m, greater<int>()); 20 sort(c, c + n); 21 for (int i=0;i<m;++i) 22 { 23 cout << b[i] << " "; 24 } 25 for (int i = 0; i < n; ++i) 26 { 27 cout << c[i] << " "; 28 } 29 return 0; 30 }