SDUT 2109 找女朋友

链接  : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2109

 

 1 #include<stdio.h>  
 2 int a[100000],temp;  
 3 int main()  
 4 {  
 5     int sort(int i,int j,int *a);  
 6     int i,j,n;  
 7     scanf("%d",&n);  
 8     for(i = 0;i < n; i++)  
 9         scanf("%d",&a[i]);  
10     sort(0,n-1,a);  
11     printf("%d",a[0]);  
12     for(i = 1;i < n; i++)  
13         printf(" %d",a[i]);  
14     printf("\n");  
15     return 0;  
16 }  
17 int sort(int i,int j,int *a)  
18 {  
19     if(i == j) return 0;  
20     int h = i,t = j,mark = 0;  
21     for(;i != j;)  
22     {  
23         if(mark % 2 == 0)  
24         {  
25             if(a[i] < a[j]) {mark = 1;temp = a[i];a[i] = a[j];a[j] = temp;}  
26             else j--;  
27         }  
28         else  
29         {  
30             if(a[j] > a[i]) {mark = 0;temp = a[i];a[i] = a[j];a[j] = temp;}  
31             else i++;  
32         }  
33     }  
34     if(i == h) sort(i+1,t,a);  
35     else if(i == t) sort(h,i-1,a);  
36     else  
37     {  
38         sort(h,i-1,a);  
39         sort(i+1,t,a);  
40     }  
41 } 

 

posted @ 2013-06-29 13:13  好小孩  阅读(298)  评论(0编辑  收藏  举报