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 丢人啊!! 0ms~~~~

Posted by 937207021 at 2011-08-09 16:03:59 on Problem 3325
#include<stdio.h>
typedef int type;
int partition(type *tt,int low,int high);
void Qsort(type *tt,int low,int high);//在头文件下;
int partition(type *tt,int low,int high)
{
	type pivotkey;
	pivotkey=tt[low];
	while(low<high){
		while(low<high && tt[high]>=pivotkey) high--;
		tt[low]=tt[high];
		while(low<high && tt[low]<=pivotkey) low++;
		tt[high]=tt[low];
	}
	tt[low]=pivotkey;
	return low;
}

void Qsort(type *tt,int low,int high)
{
	int pivot;
	if(low<high){
		pivot=partition(tt,low,high);
		Qsort(tt,low,pivot-1);
		Qsort(tt,pivot+1,high);
	}
}
int main()
{
	int i,tt[1000],n;
	int av,sum;
	while(scanf("%d",&n),n!=0)
	{
		for(i=0;i<n;i++)
			scanf("%d",&tt[i]);
		sum=0;
		av=0;
		Qsort(tt,0,n-1);//将n个数排序在主函数中;
		for(i=1;i<n-1;i++)
			sum=sum+tt[i];
		av=sum/(n-2);
		printf("%d\n",av);
	}
	return 0;
}

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