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:为什莫调用qsort函数就是wa,调用自己写的函数就是对的

Posted by frkstyc at 2005-04-27 22:54:22 on Problem 1862
In Reply To:为什莫调用qsort函数就是wa,调用自己写的函数就是对的 Posted by:shasha at 2005-04-27 22:52:13
ft,这个compare啊……无语了……怎么能转换成int*呢?明明是double*,唉……被冤枉的永远是crt

> #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