|
|
@ -231,7 +231,7 @@ use std::collections::HashMap;
|
|
|
|
let text = "hello world wonderful world";
|
|
|
|
let text = "hello world wonderful world";
|
|
|
|
|
|
|
|
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
// 根据空格来且分字符串(英文单词都是通过空格切分)
|
|
|
|
// 根据空格来切分字符串(英文单词都是通过空格切分)
|
|
|
|
for word in text.split_whitespace() {
|
|
|
|
for word in text.split_whitespace() {
|
|
|
|
let count = map.entry(word).or_insert(0);
|
|
|
|
let count = map.entry(word).or_insert(0);
|
|
|
|
*count += 1;
|
|
|
|
*count += 1;
|
|
|
|