fork download
  1. #include <unordered_map>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. stringstream f("Мама мыла мыла раму");
  11. string word;
  12. unordered_map<string, size_t> dict;
  13. while (f >> word) ++dict[word];
  14. vector<pair<string, int> > res;
  15. res.reserve(dict.size());
  16. copy(dict.begin(), dict.end(), back_inserter(res));
  17. sort(res.begin(), res.end(), [](const auto & a, const auto & b) {return a.second > b.second;});
  18. for (auto & w_c : res) cout << w_c.first << " : " << w_c.second << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
мыла : 2
раму : 1
Мама : 1