Triangle Type
Completed
Read three side lengths and print invalid, equilateral, isosceles or scalene.
Input
Three integers.
Output
One word.
Example
Input
3 3 3
Output
equilateral
Editor
C++
Hints
min({a, b, c}) and max({a, b, c}) work with an initializer list.
Solution explanation
Finding the smallest, middle and largest side avoids checking every order.
Show solution
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int lo = min({a, b, c}), hi = max({a, b, c});
int mid = a + b + c - lo - hi;
if (lo + mid <= hi) cout << "invalid\n";
else if (lo == hi) cout << "equilateral\n";
else if (lo == mid || mid == hi) cout << "isosceles\n";
else cout << "scalene\n";
return 0;
}