题解 | A-B≠C
A-B≠C
https://www.nowcoder.com/practice/78ed8bed04b94b55b525b83fc6e9757a
#include <iostream>
#include <cmath> // 使用 fabs 函数
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
// 设置一个很小的误差容忍度
// 由于输入小数点后不超过6位,我们可以用 1e-8 或 1e-9
const double EPS = 1e-9;
// 比较 a - b 和 c 是否在误差范围内相等
if (fabs((a - b) - c) < EPS)
cout << "YES";
else
cout << "NO";
return 0;
}
查看15道真题和解析