C++:登录时出错,识别大于 0 的有效三角形,提供所有三个角度

问题描述

我编写了这个程序,它通过了所有手动测试条件,但是当我在 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;
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...