交叉排序
来源:互联网 发布:如何提高淘宝宝贝排名 编辑:程序博客网 时间:2024/05/29 17:15
交叉排序
Time Limit: 1000MS Memory Limit: 32768KB
Submit Statistic Discuss
Problem Description
输入N个数,把所有奇数位置上的数从小到大排序,把偶数位置上的数从大到小排序。
Input
输入的第一行是一个正整数N(2<=N<=100)。
第二行是N个用空格隔开的整数。
Output
输出只有一行N个数,是按要求排序后的序列,用空格隔开。
Example Input
6
1 2 3 4 5 6
Example Output
1 6 3 4 5 2
Hint
Author
2011软件1-5班《程序设计基础》机试 tongjiantao
#include <iostream>#include <string>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int cmp(int a, int b){ return a>b;}int main(){ int n; int a[100], e=0; int b[100], d=0; int i; cin>>n; int dd; for(i=1; i<=n; i++) { cin>>dd; if(i%2==1) a[e++]=dd; else b[d++]=dd; } sort(a, a+e); sort(b, b+d, cmp); if(n%2==0) { for(i=0; i<(n/2); i++) { if(i==0) cout<<a[i]<<" "<<b[i]; else cout<<" "<<a[i]<<" "<<b[i]; } cout<<endl; } else { for(i=0; i<(n/2); i++) { cout<<a[i]<<" "<<b[i]<<" "; } cout<<a[e-1]<<endl; } return 0;}
阅读全文
0 0
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉--排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- 交叉排序
- noip2013货车运输(lca)
- 杭电 OJ 1720 A+B Coming
- EtherCAT State Transition
- lower_bound()返回值
- STM8S105系列单片机管脚复用配置(选项字节的配置)
- 交叉排序
- HDU-Kirinriki
- JavaScript Canvas 绘图
- junit测试、内省、BeanUtils
- 数据中心的女性如何工作的?
- Spring Data JPA调用存储过程实例
- C++11 新的计时方法——std::chrono 大法好
- PowerOj 2392(树状数组 or CDQ分治)
- 第三篇:JAVA网络编程之应用程序协议中消息的成帧与解析(含代码)