SDUT1591交叉排序

时间:2023-03-09 16:29:28
SDUT1591交叉排序

http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1591&cid=1187

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std ;
int main()
{
int n ;
int a[] ;
scanf("%d",&n) ;
for(int i = ; i <= n- ; i++)
scanf("%d",&a[i]) ;
int sh[] ;
int h = ;
for(int i = ; i <= n- ; i += )
{
sh[h++] = a[i] ;
}
int ch[] ;
int hh = ;
for(int i = ; i <= n- ; i += )
ch[hh++] = a[i] ;
sort(sh,sh+h) ;
sort(ch,ch+hh) ;
reverse(ch,ch+hh) ;//一定要先sort一下,因为这个是转置的
int oo = ;
for(int i = ; i <= h- ; i++){
a[oo] = sh[i] ;
oo += ;
}
int ooo = ;
for(int i = ; i <= hh- ; i++)
{
a[ooo] = ch[i] ;
ooo += ;
}
for(int i = ; i <= n- ; i++)
printf("%d ",a[i]) ;
printf("%d\n",a[n-]) ;
return ;
}