OJ_1117
来源:互联网 发布:自动同步时间软件 编辑:程序博客网 时间:2024/06/05 14:46
#include<iostream>#include<algorithm>#define N 10using namespace std;bool comp1(const int &a,const int &b){ return a>b;//从大到小 }bool comp2(const int &a,const int &b){ return a<b;//从大到小 }int main(){ int a[N]; int i; while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8]>>a[9]){ int od=0,ev=0; int odd[N],even[N]; for(i=0;i<N;i++){ if(a[i]%2==0){ even[ev++]=a[i]; } else odd[od++]=a[i]; } sort(even,even+ev,comp2); sort(odd,odd+od,comp1); if(od){ cout<<odd[0]; for(int i=1;i<od;i++) cout<<' '<<odd[i]; for(int i=0;i<ev;i++) cout<<' '<<even[i]; cout<<endl; }else { cout<<even[0]; for(int i=1;i<ev;i++) cout<<' '<<even[i]; cout<<endl; } } return 0; }
分别排序,然后分别输出
- 题目描述:
输入10个整数,彼此以空格分隔。重新排序以后输出(也按空格分隔),要求:
1.先输出其中的奇数,并按从大到小排列;
2.然后输出其中的偶数,并按从小到大排列。
- 输入:
任意排序的10个整数(0~100),彼此以空格分隔。
- 输出:
可能有多组测试数据,对于每组数据,按照要求排序后输出,由空格分隔。
- 样例输入:
4 7 3 13 11 12 0 47 34 98
- 样例输出:
47 13 11 7 3 0 4 12 34 98
- 提示:
1. 测试数据可能有很多组,请使用while(cin>>a[0]>>a[1]>>...>>a[9])类似的做法来实现;
2. 输入数据随机,有可能相等。
0 0
- OJ_1117
- ubuntu man 函数或者系统命令失败(如man ls)解决办法
- 图解U-Boot(没有SPL的uboot早期版本):第二阶段源码分析
- OJ_1116
- mysql配置mysql-proxy读写分离
- iOS7教程系列:自定义导航转场动画以及更多
- OJ_1117
- windows下安装python的某些扩展可能用得到的解决import error的扩展...
- POJ 2386 Lake Counting DFS水水
- 入门训练 Fibonacci数列
- Hadoop 2.0.5-alpha集群搭建02-Hadoop集群配置
- 自己编写SqlHelper类
- OJ_1118 数制转换
- WWDC 2013 Session笔记--iOS7中的ViewController切换
- iOS:关于浅拷贝和深拷贝