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:c语言AC了 但C++死活WA.主程序都是一句,有兴趣的来看看WHY??!!In Reply To:c语言AC了 但C++死活WA.主程序都是一句,有兴趣的来看看WHY??!! Posted by:20054959 at 2007-03-15 21:04:27 > C++: //WA > while(cin>>n>>p) > cout<<floor(pow(p,1.0/n))<<endl; > C: //AC > while(scanf("%lf%lf",&n,&p)==2) > printf("%.0lf\n",pow(p,1.0/n)); 改成: while(cin>>n>>p) cout<<(int)(pow(p,1.0/n)+0.5)<<endl; 即可。 原因是floor函数取较小整数,若结果为:3.9999999这种形式的就错了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator