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 |
为什么使用qsort过不了,改用冒泡就过了#include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <iomanip.h> double weight[101]; int compare(const void *arg1,const void *arg2) { return *(double *)arg1<*(double *)arg2; } int main() { int N,i,j; double total,temp; total=0; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); cin>>N; for(i=0;i<N;i++) cin>>weight[i]; qsort(weight,N,sizeof(double),compare); for(i=0;i<N;i++) for(j=i+1;j<N;j++) if (weight[i]<weight[j]){ temp=weight[i]; weight[i]=weight[j]; weight[j]=temp; } total=weight[0]; for(i=1;i<N;i++) total=2*sqrt(total*weight[i]); cout<<total<<endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator