有两个关于ACM的小问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 10:46:06
两个问题 怎么也不明白
#include<iostream>
#define PI 3.1415927
using namespace std;
int main()
{
cout.precision(3);
float r;
while(cin>>r)
{
cout<<fixed<<4.0/3*PI*r*r*r<<endl;

}
return 0;
}
链接地址
http://acm.hdu.edu.cn/showproblem.php?pid=2002
就是计算体积 提交后是 wrong answer 为什么呢???

另外一个链接地址http://acm.hdu.edu.cn/showproblem.php?pid=2003
是求绝对值
#include<stdio.h>
int main()
{
float a;
while(scanf("%f",&a))
{

printf("%.2f\n",(a<0?-a:a));
}
return 0;
}

这个提交后是Output Limit Exceeded
小弟刚开始ACM 望前人指点

第一个:
PI最好能到15位以后, r用double
输出加上浮点数修正值
cout << fixed << 4.0/3*PI*r*r*r+1e-8 << endl;

第二个:
改成while(scanf("%f",&a)!=EOF)