#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
using std::cin;
using std::cout;
using std::endl;
using std::sort;
using std::string;
using std::vector;
using std::map;
class wordcount
{
public:
wordcount(string s,int t):word(""),times(0)
{
word=s;
times=t;
}
int operator < (wordcount &w){return times<w.times;}
int operator > (wordcount &w){return times>w.times;}
string word;
int times;
};
int Comper( wordcount str1, wordcount str2 )
{
return str1 > str2;
}
int main()
{
string s;
map<string,int> word;
vector<wordcount> word_count;
cout<<"Place enter your string "
"end_of_file of \"Ctrl+Z\":"<<endl;
while(cin>>s)
word[s]++;
for(map<string,int>::iterator itr=word.begin();itr!=word.end();itr++)
{
wordcount w(itr->first,itr->second);
word_count.push_back(w);
}
sort(word_count.begin(),word_count.end(),Comper);
for(vector<wordcount>::size_type i=0;i<word_count.size();i++)
{
cout<<word_count[i].word<<" "<<word_count[i].times<<endl;
}
system("pause");
return 0;
}