それぞれの単語が何回出てくるかを map にして返す count_words(words) を書きましょう。
count_words({"cat", "dog", "cat"})→{'cat': 2, 'dog': 1}count_words({})→{}map<string, int> count_words(const vector<string> &words)#include <map>
#include <string>
#include <vector>
using namespace std;
map<string, int> count_words(const vector<string> &words) {
map<string, int> seen;
for (const string &w : words) {
// ここにコードを書く:この単語の回数に 1 を足す
}
return seen;
}
実行すると例で試せます。よさそうなら提出しましょう。