【发布时间】:2022-01-24 04:40:08
【问题描述】:
这是我的代码。它使用自定义示例输入正确运行,但在我提交时失败。 另外我不知道如何添加问题中给出的约束。 问题的链接是:https://www.codechef.com/submit/HS08TEST。
#include <iostream>
#include<iomanip>
using namespace std;
int main() {
// your code goes here
int r;
cin >> r;
float balance;
cin >> balance;
float amount;
if (r%5==0 && r<balance ){
amount = float(balance - r - 0.5);
cout << fixed;
cout << setprecision(2) << amount;
}
else {
cout<< fixed;
cout << setprecision(2) << balance;
}
return 0;
}
【问题讨论】:
-
警惕从编码网站学习 C++。他们经常助长坏习惯。虽然您可能会知道前两个输入将是
int和float,但您永远不会不检查std::cin后面的数字值的流状态。另见Why is “using namespace std;” considered bad practice?
标签: c++