问题描述
我编写了这个程序,它通过了所有手动测试条件,但是当我在 IDE 上在线提交时显示“错误答案”。 约束 0≤a,b,c≤180
#include <iostream>
using namespace std;
int main() {
// your code goes here
double a,c;
cin>>a>>b>>c;
if(a+b+c==180)
cout<<"YES";
else
cout<<"NO";
return 0;
}
解决方法
当 a,bc 为零且 a+b+c=180 时,上述代码无法给出正确答案。 所以,
int main()
{
// your code goes here
double a,b,c;
cin>>a>>b>>c;
//add the below statement
if((a!=0)&&(b!=0)&&(c!=0)){
if(a+b+c==180)
cout<<"YES";
else
cout<<"NO";
}
else{
cout<<"NO";
}
return 0;
}
,
int main()
{
// your code goes here
double a,c;
cin>>a>>b>>c;
//made the changes with the help of suggestion from the forum
if((a>0)&&(b>0)&&(c>0)&&(a+b+c==180))
cout<<"YES";
else
cout<<"NO";
return 0;
}