Connection Status:
Competition Arena > TriangleType
SRM 247 · 2005-06-18 · by lars2520 · Simple Math
Class Name: TriangleType
Return Type: String
Method Name: type
Arg Types: (int, int, int)
Problem Statement

Problem Statement

In Euclidean Geometry, triangles can be categorized into one of three types based on their angle measures. A triangle is acute if all three angles are less than 90 degrees. A triangle is obtuse if one angle is greater than 90 degrees. Lastly, a triangle with one angle at exactly 90 degrees is a right triangle.

It could also be the case that three positive integers can not possibly form the side-lengths of a triangle. This happens when the length of one side is equal to or larger than the sum of the lengths of the other two sides, because it would not be possible to connect the end points of the three sides in such a way that a triangle was formed.

Write a method that takes as input three positive integer side-lengths of a triangle. Return "IMPOSSIBLE" if a triangle cannot be formed. Return "ACUTE" if the triangle is acute, "OBTUSE" if the triangle is obtuse, and "RIGHT" if the triangle is right.

Notes

  • For a triangle with side-lengths x, y, and z and x <= y <= z. * The triangle is right if x*x + y*y = z*z.* The triangle is obtuse if x*x + y*y < z*z.* The triangle is acute if x*x + y*y > z*z.* It is impossible to have x + y <= z.

Constraints

  • a, b, and c are between 1 and 10,000, inclusive.
Examples
0)
3
4
5
Returns: "RIGHT"
1)
3
4
4
Returns: "ACUTE"
2)
3
4
6
Returns: "OBTUSE"
3)
7
4
3
Returns: "IMPOSSIBLE"
4)
17
13
11
Returns: "ACUTE"

Submissions are judged against all 33 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TriangleType with a public method string type(int a, int b, int c) · 33 test cases · 2 s / 256 MB per case

Submitting as anonymous