P5717 【深基3.习8】三角形分类

https://www.luogu.com.cn/problem/P5717

#include 
using namespace std;

int main()
{
    int a(0),b(0),c(0);
    cin >> a >> b >> c;
    if (a > c)
    {
        int tmp = a;
        a = c;
        c = tmp;
    }
    if (b > c)
    {
        int tmp = b;
        b = c;
        c = tmp;
    }
    if (a > b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }
    // a < b < c
    if (a+b <= c)
    {
        cout << "Not triangle" << endl;
        return 0;
    }
    bool bRight = false;
    bool bAcute = false;
    bool bObtuse = false;
    bool bIsosceles = false;
    bool bEquilateral = false;
    if (a==b && b==c)
    {
        bEquilateral = true;
    }
    if (a==b || b==c)
    {
        bIsosceles = true;
    }
    if (a*a + b*b == c*c)
    {
        bRight = true;
    }
    else if (a*a + b*b > c*c)
    {
        bAcute = true;
    }
    else 
    {
        bObtuse = true;
    }
    if (bRight)
        cout << "Right triangle" << endl;
    if (bAcute)
        cout << "Acute triangle" << endl;
    if (bObtuse)
        cout << "Obtuse triangle" << endl;
    if (bIsosceles)
        cout << "Isosceles triangle" << endl;
    if (bEquilateral)
        cout << "Equilateral triangle" << endl;
    return 0;
}

 

你可能感兴趣的:(洛谷)