Schreib count_words(words), das eine map zurückgibt, wie oft jedes Wort vorkommt.
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) {
// dein Code hier: zähl 1 zur Anzahl dieses Worts dazu
}
return seen;
}
Ausführen testet die Beispiele. Wenn sie passen, drück auf Abgeben.