fork(1) download
  1. #include <algorithm>
  2. #include <cctype>
  3. #include <iostream>
  4. #include <regex>
  5. #include <string>
  6. #include <unordered_map>
  7.  
  8. int main()
  9. {
  10. const std::string str = "Eniki,beniki, eli vareniki; Eli i eli poka ne doeli beniki vareniki.";
  11. const std::regex reg("\\w+");
  12.  
  13. std::unordered_map<std::string, int> words;
  14. for (std::sregex_iterator next(str.begin(), str.end(), reg), end; next != end; ++next)
  15. {
  16. std::string word = next->str();
  17. std::transform(word.begin(), word.end(), word.begin(), tolower);
  18. ++words[word];
  19. }
  20.  
  21. for (auto p : words)
  22. std::cout << p.first << " " << p.second << std::endl;
  23. }
Success #stdin #stdout 0s 3324KB
stdin
Standard input is empty
stdout
doeli 1
ne 1
poka 1
eli 3
i 1
vareniki 2
beniki 2
eniki 1