GG:整数奇偶排序
时间:2020-12-05 09:26:35
收藏:0
阅读:17
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
-
给定10个整数的序列,要求对其重新排序。排序要求:
1.奇数在前,偶数在后;
2.奇数按从大到小排序;
3.偶数按从小到大排序。
- 输入
- 输入一行,包含10个整数,彼此以一个空格分开,每个整数的范围是大于等于0,小于等于100。
- 输出
- 按照要求排序后输出一行,包含排序后的10个整数,数与数之间以一个空格分开。
- 样例输入
-
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 }
原文:https://www.cnblogs.com/dss-99/p/14088347.html
评论(0)