Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:为什莫调用qsort函数就是wa,调用自己写的函数就是对的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator