我不得不计算向量的单词,然后将其放在对单词进行计数的地图中。然后,功能showFrequencies
必须显示/打印地图。
map<string, int>CountWords(vector<string> words) {
map<string, int> count;
for(auto i = words.begin(); i != words.end(); i++) {
count[*i]++;
}
return count;
}
void showFrequencies(CountWords(vector<string> name)) {
for (map<string, int>::const_iterator it = count.begin(); it !=
count.end(); ++it) {
cout << it->first << "\t" << it->second;}
}
int main(){
vector<string> words = {"hello", "you", "hello", "me", "chipolata", "you"};
showFrequencies(CountWords(words));
return 0;
}
答案 0 :(得分:2)
void showFrequencies(CountWords(vector<string> name)) {
应该是
void showFrequencies(const map<string, int>& name) {