Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:第一次 一次就ac 纪念一下!!! 哈哈~~~ 代码贴上

Posted by HXS2011 at 2011-08-03 14:31:00 on Problem 2388
In Reply To:第一次 一次就ac 纪念一下!!! 哈哈~~~ 代码贴上 Posted by:937207021 at 2011-07-25 20:23:18
这是我写的代码,为什么出错呢??
#include<stdio.h>
#include<malloc.h>

int Partiton(int *a,int low,int high)
{
	int key=a[low];
	if(low<high)
	{
		while(low<high && a[high]>=key)
		{
			--high;
		}
		if(low<high)
		{
			a[low]=a[high];
		}
		while(low<high && a[low]<=key)
		{
			++low;
		}
		if(low<high)
		{
			a[high]=a[low];
		}
	}
	a[low]=key;
	return low;
}

void Quick_Sort(int *a,int low, int high)
{
	int pos;
	if(low<high)
	{
		pos=Partiton(a,low,high);
		Quick_Sort(a,low,pos);
		Quick_Sort(a,pos+1,high);
	}
}
	
int main()
 {
	 int n;
	 int i;
	 int *a;
//	freopen("a.txt","r",stdin);
	 while(scanf("%d",&n)!=EOF && n!=0)
	 {
		 a=(int*)malloc(sizeof(int)*n);
		 for(i=0;i< n;i++)
		 {
			 scanf("%d",&a[i]);
		 }
		 Quick_Sort(a,0,n-1);
		 printf("%d\n",a[n/2]);
		 free(a);
	 }
	 return 1;
 }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator