您的位置:首页 > 其它

hdu 1040 As Easy As A+B(快排练习水题~)

2010-11-16 21:18 302 查看
自己第一次不看书写成快排~~欧也~~~



PE数次 = =。。。最后一个不要加空格 = =。。



#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <memory.h>
using namespace std;
int n;
int Partition(int a[],int p, int r)
{
	int i = p-1;
	int x = a[r];
	for(int j=p; j<r; j++)
		if( a[j] <= x )
		{
			i++;
			swap(a[i],a[j]);
		}
	swap(a[i+1],a[r]);
	return i+1;
}
void QuickSort(int a[],int p,int r)
{
	if( p < r )
	{
		int q = Partition(a,p,r);
		QuickSort(a,q+1,r);
		QuickSort(a,p,q-1);
	}
}
int main(void)
{
	int ncases;
	int a[1001];
	scanf("%d",&ncases);
	while( ncases-- )
	{
		scanf("%d",&n);
		for(int i=1; i<=n; i++)
			scanf("%d",&a[i]);
		QuickSort(a,1,n);
		for(int i=1; i<n; i++)	
			printf("%d ",a[i]);
		printf("%d",a
);
		printf("/n");
	}
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: