Go: Classify a triangle

Several conditions together describe a shape.

What to build

A program that classifies triangles from their sides.

Requirements

  • Read n, then n lines with three whole numbers (the sides).
  • Print invalid if a side is not positive or the two shorter sides do not add up to more than the longest.
  • Otherwise print equilateral (three equal sides), isosceles (exactly two equal) or scalene (all different).
  • If a * a + b * b == c * c for the sorted sides, add right after the word.

Input

Line 1: n. Then n lines with three whole numbers.

Output

n lines.

Constraints

1 ≤ n ≤ 30; each side is between -1000 and 1000.

Example

Input:

4
3 4 5
2 2 2
5 5 8
1 2 3

Output:

scalene right
equilateral
isosceles
invalid

Why it works

After sorting, the check a + b > c is enough to test all three triangle rules, and the right-angle test needs only the squares of the sorted sides.

Examples

Example 1 · Input
4
3 4 5
2 2 2
5 5 8
1 2 3
Expected output
scalene right
equilateral
isosceles
invalid
Example 2 · Input
3
7 10 5
0 4 4
13 12 5
Expected output
scalene
invalid
scalene right

Hints

Hint 1

Sort the three sides first (swap with a, b = b, a), so c is the longest.

Hint 2

It is valid only when a is positive and a + b is greater than c.

Solution

Show one correct solution (try it yourself first)
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		if a > b {
			a, b = b, a
		}
		if b > c {
			b, c = c, b
		}
		if a > b {
			a, b = b, a
		}
		if a <= 0 || a+b <= c {
			fmt.Println("invalid")
			continue
		}
		kind := "scalene"
		if a == c {
			kind = "equilateral"
		} else if a == b || b == c {
			kind = "isosceles"
		}
		if a*a+b*b == c*c {
			kind += " right"
		}
		fmt.Println(kind)
	}
}

▶ Open this solution in the compiler

Lesson: Conditions and switch →