Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- using namespace std;
- map<string, int> ComputeTermFreqs(const vector<string>& terms) {
- // реализуйте функцию
- map<string, int> result;
- for (const string& word : terms) {
- int counter = 1;
- result[word]+=counter;
- }
- return result;
- }
- int main() {
- const vector<string> terms = {"first"s, "time"s, "first"s, "class"s};
- for (const auto& [term, freq] : ComputeTermFreqs(terms)) {
- cout << term << " x "s << freq << endl;
- }
- // вывод:
- // class x 1
- // first x 2
- // time x 1
- }
Advertisement
Add Comment
Please, Sign In to add comment