Think:
1知识点:sort()实现快速排序
2思考:通过两次快速排序实现交叉排序,分治思想
以下为Accepted代码
#include <bits/stdc++.h>
using namespace std;
int a[104], b[104];
int main(){
int n, i, tp1, tp2;
tp1 = tp2 = 0;
scanf("%d", &n);
for(i = 1; i <= n; i++){
if(i & 1)
scanf("%d", &a[tp1++]);
else
scanf("%d", &b[tp2++]);
}
sort(a, a+tp1);
sort(b, b+tp2, greater<int>());
int op1 = 0, op2 = 0;
for(i = 1; i <= n; i++){
if(i & 1)
printf("%d%c", a[op1++], i == n? '\n': ' ');
else
printf("%d%c", b[op2++], i == n? '\n': ' ');
}
return 0;
}
/***************************************************
User name:
Result: Accepted
Take time: 0ms
Take Memory: 244KB
Submit time: 2017-07-15 10:41:56
****************************************************/