Quick actions

cmd+k|ctrl+k

Navigation

Languages

findOccurencesOfWords

Snippet info

Language

Cpp

Visibility

public

Author

preeti.gaur1790

Created

2022-05-29T07:24:40.268207Z

Updated

2022-05-29T07:24:40.268207Z

#include <iostream>
#include<sstream>
#include<unordered_map>
using namespace std;


 

void findOccurencesOfWords(string s) {
    stringstream ss(s);
    string word;
    unordered_map<string, int> um;
    while (ss >> word) {
        um[word]++;
    }
    
    for(auto it : um) {
        cout << "(" << it.first << " : " << it.second << ")" << endl;
    }
    
}
 
// Driver program
int main()
{
    string str = "geeks for geeks geeks quiz practice qa for";
    findOccurencesOfWords(str);
    //cout << str;
    return 0;
}
INFO