Counting the frequency of words in a string.

I've written a code on counting the frequency of words in a string which is given below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    map<string, int> m;
    string str;

    while(cin>>str)
    {
        if(str == "end") break;
        m[str]++;

        cout<<str<<" frequency = "<<m[str]<<endl;
    }

    return 0;
}



It gives me output like this- http://ctrlv.in/422823

But I want only the number of maximum frequency of a word as output...not the frequency that counts in every iteration.

I want the output to be like the following-

1
2
3
4
5
i frequency = 4
me frequency = 1
we frequency = 3
you frequency = 2
can  frequency = 1


Now how to write that code?
closed account (28poGNh0)
sorry ,I am still working on it
Last edited on
Topic archived. No new replies allowed.