TLE求大佬指点
查看原帖
TLE求大佬指点
808298
ZFGJFUB楼主2023/2/12 12:45
#include<stdio.h>
#include<stdlib.h>
int a[100000],n;

void s(int head,int tail)//排序 
{
	int base = head,i,j,box;
	while(head<tail)//基准数归位
	{
		for(i = head;a[i]>base;i)//从左至右寻找大于基准数的数 
		{
			i++;
		}
		for(j = head;a[j]<base;j)//从右至左寻找小于于基准数的数 
		{
			j--;
		}
		//交换a[i]、a[j]
		box = a[j];
		a[j] = a[i];
		a[i] = box;
		if(i>=j)//相遇,基准数归位至a[i] 
		{
			//交换a[head]与a[i] 
			box = a[head];
			a[head] = a[i];
			a[i] = box; 
		}	
	}
	//对子数集进行排列
	s(head,i-1);
	s(i+1,tail); 
} 

int main(void)
{
	scanf("%d",&n);//确定大小 
	
	for(int i = 0;i<n;i++)//读入 
	{
		scanf("%d",a+i);
	}
	
	s(0,n-1);//排序 
	
	for(int i = 0;i<n;i++)//输出 
	{
		printf("%d",a[i]);
	}
	
	return 0;
}
2023/2/12 12:45
加载中...