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

27 lines
716 B

package cap3
type Subject int
type Student int
func Ex14(subjectPassedStudentMap map[Subject]Student) []Student {
result := make([]Student, 0)
// 学生及格科目数记录
studentRecord := map[Student]int{}
for _, student := range subjectPassedStudentMap {
// 对当前学生及格科目计数
if _, exists := studentRecord[student]; !exists {
studentRecord[student] = 1
} else {
studentRecord[student]++
}
// 学生及格科目数已达到传入的科目数,即为全科及格
if studentRecord[student] == len(subjectPassedStudentMap) {
result = append(result, student)
}
}
return result
}