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/ex12.go

22 lines
371 B

package cap3
type HeightGrade int
// Ex12 身高统计,这里也是用的hashmap存结果
func Ex12(heights []int) []int {
6 months ago
result := make([]int, 8)
for _, height := range heights {
// 身高映射,上下限调整
mapping := height/5 - 29
if mapping < 0 {
mapping = 0
} else if mapping > 7 {
mapping = 7
}
6 months ago
result[mapping]++
}
6 months ago
return result
}