请看下面的代码
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double balance=0;
int withdraw = 0;
double const bankCharges = 0.5;
cin >> withdraw >> balance;
if(withdraw%5==0 && balance>(withdraw+bankCharges))
{
cout << fixed << setprecision(2) << ((balance)-(withdraw+bankCharges)) << endl;
}
else if(withdraw%5!=0 || withdraw>balance)
{
cout << fixed <<setprecision(2) << balance << endl;
}
return 0;
}上面的代码是为了解决以下挑战而创建的
http://www.codechef.com/problems/HS08TEST
如您所见,我的代码提供了正确的答案。但是测试引擎显示“错误答案”!为什么?请帮帮我!
发布于 2013-02-13 13:52:43
永远不要离开if,else if块而不带else条件,即使只有很小的可能性到达那里。将else条件添加到代码中。
if(withdraw%5==0 && balance>(withdraw+bankCharges))
{
cout << fixed << setprecision(2) << ((balance)-(withdraw+bankCharges)) << endl;
}
else if(withdraw%5!=0 || withdraw>balance)
{
cout << fixed <<setprecision(2) << balance << endl;
}
else
{
//Do something
}https://stackoverflow.com/questions/14847102
复制相似问题