SDUT 2109 找女朋友

来源:互联网 发布:大数据分析软件 编辑:程序博客网 时间:2024/04/29 01:05

链接  : 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 } 

 

原创粉丝点击