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 |
float -->double 就过了,#include <stdio.h> #include <stdlib.h> int cmp(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main() { int num[250001]; int n,i; double ans;//float 过不了 scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",num+i); } qsort(num,n,sizeof(int),cmp); if(n%2==0) { ans=num[n/2]/2.0+num[n/2-1]/2.0;//(double)(num[n/2]+num[n/2-1])/2.0 也无法过,括号中的加法运算是在int范围内进行的,在进行double强制类型转换之前的int两个int类型相加可能超出int类型的范围 } else { ans=num[n/2]; } printf("%.1lf",ans); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator