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 }