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

为什莫调用qsort函数就是wa,调用自己写的函数就是对的

Posted by shasha at 2005-04-27 22:52:13 on Problem 1862
#include<iostream.h>
#include<math.h>
#include<iomanip.h>
#include<stdlib.h>
int cmp ( const void * ,const void * );

int main(){
	int  number, num;
	double weight;
	double * a;
	

	cin>>number;
	num=number-1;
	
	a= new double [number];
	
	for(int i=0; i<number; i++){
		cin>>weight;
		a[i]=weight;
	}	
	qsort (a,number,sizeof ( double ),cmp );
	for(int j=0; j<num&&number>=0; j++){
		a[number-2]=2*sqrt(a[number-2]*a[number-1]);
		number--;
	}
   	cout<<setiosflags(ios::fixed|ios::showpoint);
	cout<<setprecision(3)<<a[0];
	delete [] a;
    return 0;
}

int cmp ( const void *a ,const void *b ) 
{
	int *m = (int *)a, *n = (int *)b ;
	if ( *m > *n )
		return 1 ;
	else if ( *m == *n )
		return 0 ;
	else if ( *m < *n )
		return -1;
	else
		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