SDUT1591交叉排序

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

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std ;
 7 int main()
 8 {
 9     int n ;
10     int a[110] ;
11     scanf("%d",&n) ;
12     for(int i = 0 ; i <= n-1 ; i++)
13     scanf("%d",&a[i]) ;
14     int sh[100] ;
15     int h = 0 ;
16     for(int i = 0 ; i <= n-1 ; i += 2)
17     {
18         sh[h++] = a[i] ;
19     }
20     int ch[100] ;
21     int hh = 0 ;
22     for(int i = 1 ;  i <= n-1 ; i += 2)
23     ch[hh++] = a[i] ;
24     sort(sh,sh+h) ;
25     sort(ch,ch+hh) ;
26     reverse(ch,ch+hh) ;//一定要先sort一下,因为这个是转置的
27     int oo = 0 ;
28     for(int i = 0 ; i <= h-1 ; i++){
29     a[oo] = sh[i] ;
30     oo += 2 ;
31     }
32     int ooo = 1 ;
33     for(int i = 0 ; i <= hh-1 ; i++)
34     {
35         a[ooo] = ch[i] ;
36         ooo += 2 ;
37     }
38     for(int i = 0 ; i <= n-2 ; i++)
39     printf("%d ",a[i]) ;
40     printf("%d
",a[n-1]) ;
41     return 0 ;
42 }
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3162749.html