4 条题解

  • 0
    @ 2025-10-27 22:29:03

    写了个最麻烦的

    #include<stdio.h>
    #include<string.h>
    
    void swap(int *a, int *b) {
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    
    void quick_sort(int tot[],int l,int r)
    {
    	if(l>=r){
    		return;
    	}	
    		int q=tot[l];
    		int i=l-1,j=r+1;
    		while(i<j){
    			do i++;while(tot[i]<q);
    			do j--;while(tot[j]>q);
    			if(i<j) swap(&tot[i],&tot[j]);
    		}	
    	
    	quick_sort(tot,l,j);
    	quick_sort(tot,j+1,r);
    }
    
    int main(){
    	
    	int n;
    	scanf("%d",&n);
    	
    	int tot[1000];
    	
    	int i;
    	for(i=0;i<n;i++){
    		scanf("%d",&tot[i]);
    	}
    	
    	quick_sort(tot,0,n-1);
    	
    	for(i=0;i<n;i++){
    		printf("%d ",tot[i]);
    	}
    	return 0;
    } 
    

    信息

    ID
    247
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    409
    已通过
    191
    上传者