Triangle Classification (APCS 2016-10 Beginner)
Points 100 1.0s 256MBesides being the most basic polygon, a triangle can be further classified as an obtuse triangle, a right triangle, or an acute triangle. Given the lengths of three segments, the following formulas determine whether the three segments can form a triangle, and if so, which type it is.
Hint: let \(a\), \(b\), \(c\) be the three segment lengths with \(c\) being the largest. Then
- If \(a + b \le c\), the three segments cannot form a triangle
- If \(a^2 + b^2 < c^2\), the three segments form an obtuse triangle
- If \(a^2 + b^2 = c^2\), the three segments form a right triangle
- If \(a^2 + b^2 > c^2\), the three segments form an acute triangle
Write a program that reads the lengths of three segments, determines whether they can form a triangle, and if so, outputs the type of the triangle.
Input
The input consists of a single line containing three positive integers, separated by exactly one space.
Constraints:
- All three positive integers are less than \(30001\) (i.e. between \(1\) and \(30000\))
Output
Output two lines:
The first line prints the three positive integers in non-decreasing order, with exactly one space between adjacent numbers and no trailing space after the last number;
The second line prints the type of the triangle:
- If the segments cannot form a triangle, print
No; - If they form an obtuse triangle, print
Obtuse; - If they form a right triangle, print
Right; - If they form an acute triangle, print
Acute.
Scoring
The time limit for each test case is \(1\) second; your score is the sum over the test cases you pass.
Sample Input 1
3 4 5
Sample Output 1
3 4 5
Right
Sample Explanation 1
When \(a^2 + b^2 = c^2\) holds, it is a right triangle.
Sample Input 2
101 100 99
Sample Output 2
99 100 101
Acute
Sample Explanation 2
The side lengths are printed in non-decreasing order; when \(a^2 + b^2 > c^2\) holds, it is an acute triangle.
Sample Input 3
10 100 10
Sample Output 3
10 10 100
No
Sample Explanation 3
Since the segments cannot form a triangle, the second line must print No.
Source
APCS programming exam, October 29, 2016, Problem 1.
Log in to write and submit code.
Log in