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:小弟很菜,望大牛帮忙看一下错在哪里?In Reply To:Re:小弟很菜,望大牛帮忙看一下错在哪里? Posted by:smark at 2007-03-05 21:14:47 > 后来我再看了一下,发现了问题,不过不是排序的问题,是精度的问题吧(我想) > 把 a[101]改为 double就AC了,不过还是谢谢你! 并不要求读入的数据是double,int 就可以了,我把你的排序改了一下就AC了,如下: #include<iostream.h> #include<math.h> #include<stdio.h> int main() { int t,a[101],i,j; double res; cin>>t; if(t>1) { for( i=0;i<t;i++) { cin>>a[i]; } for(i=0;i<t-1;i++) { for( j=0;j<t-1-i;j++) { if(a[j]<a[j+1]) { int temp; temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } res=2*sqrt(a[0]*a[1]); if(t>2) { for(i=2;i<t;i++) { res=2*sqrt(res*a[i]); } } printf("%.3f\n",res); } else if(t==1) { cin>>res; printf("%.3f\n",res); } //while(1); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator