Advertisement
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>freq_doc;
- for(const auto& term: terms){
- freq_doc[term]++;
- }
- return freq_doc;
- }
- 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
Advertisement