You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lavos/cap3/ex30.go

38 lines
1.0 KiB

7 months ago
package cap3
import "math"
type Ex30TriangleType int
const (
Ex30TriangleTypeNone Ex30TriangleType = iota // 不是三角形
Ex30TriangleTypeNormal Ex30TriangleType = iota // 普通三角形
Ex30TriangleTypeIsosceles Ex30TriangleType = iota // 等腰三角形
Ex30TriangleTypeEquilateral Ex30TriangleType = iota // 等边三角形
Ex30TriangleTypeRight Ex30TriangleType = iota // 直角三角形
7 months ago
)
func Ex30(nums []float64) Ex30TriangleType {
a, b, c := nums[0], nums[1], nums[2]
if a <= 0 || b <= 0 || c <= 0 || a+b <= c || a+c <= b || b+c <= a {
return Ex30TriangleTypeNone
}
if a == b && b == c {
return Ex30TriangleTypeEquilateral
}
if a == b || a == c || b == c {
return Ex30TriangleTypeIsosceles
}
if math.Pow(a, 2)+math.Pow(b, 2) == math.Pow(c, 2) ||
math.Pow(a, 2)+math.Pow(c, 2) == math.Pow(b, 2) ||
math.Pow(b, 2)+math.Pow(c, 2) == math.Pow(a, 2) {
return Ex30TriangleTypeRight
} else {
return Ex30TriangleTypeNormal
}
7 months ago
}