作业:
https://github.com/cos418atPrinceton/assignments_template.git
课程:
https://www.cs.princeton.edu/courses/archive/spring21/cos418/schedule.html
Assignment1-1:
在这里插入代码片
```// Find the top K most common words in a text document.
// path: location of the document
// numWords: number of words to return (i.e. k)
// charThreshold: character threshold for whether a token qualifies as a word,
// e.g. charThreshold = 5 means "apple" is a word but "pear" is not.
// Matching is case insensitive, e.g. "Orange" and "orange" is considered the same word.
// A word comprises alphanumeric characters only. All punctuation and other characters
// are removed, e.g. "don't" becomes "dont".
// You should use `checkError` to handle potential errors.
func topWords(path string, numWords int, charThreshold int) []WordCount {
// TODO: implement me
// HINT: You may find the `d` and `strings.ToLower` functions helpful
// HINT: To keep only alphanumeric characters, use the regex "[^0-9a-zA-Z]+"
//读取
s,err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
sLower :=strings.ToLower(string(s)) //转小写
ss :=strings.Fields(sLower) //拆分字符串
var wordC [] WordCount
for i:=0;i=charThreshold{ //必须大于给定的长度才算单词
flag:=0
for i:=0;i
验证通过



