#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
//自定义stable_sort()的仿函数,比较count
struct Greater
{
bool operator()(const pair<string, int>& p1, const pair<string, int>& p2)
{
return p1.second > p2.second;
}
};
//单词分割
void WordsSlice(string& sentence, vector<string>& words)
{
sentence[0] = tolower(sentence[0]);
size_t beginPos = 0, endPos = 0;
while(endPos != string::npos)
{
endPos = sentence.find(' ', beginPos);
if(endPos != string::npos)
{
words.push_back(sentence.substr(beginPos, endPos - beginPos));
beginPos = ++endPos;
}
}
endPos = sentence.find('.', beginPos);
words.push_back(sentence.substr(beginPos, endPos - beginPos));
}
//单词计数和排序
vector<pair<string, int>> WordsCountAndSort(vector<string>& words, map<string, int>& countMap)
{
for(const auto& word : words) {
countMap[word]++;
}
vector<pair<string, int>> countV(countMap.begin(), countMap.end());
stable_sort(countV.begin(), countV.end(), Greater());
return countV;
}
void ResOutput(const vector<pair<string, int>>& countV)
{
for(const auto& e : countV) {
cout << e.first << ':' << e.second << endl;
}
}
int main()
{
string sentence;
getline(cin, sentence); //输入句子
vector<string> words;
WordsSlice(sentence, words); //分割单词
map<string, int> countMap;
vector<pair<string, int>> countV = WordsCountAndSort(words, countMap); //单词计数和排序
ResOutput(countV); //结果输出
return 0;
}