fork(2) download
  1. #include <algorithm>
  2. #include <codecvt>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <locale>
  6. #include <string>
  7. #include <tuple>
  8. #include <unordered_map>
  9. #include <vector>
  10.  
  11. using namespace std;
  12.  
  13. int main(int argc, const char* argv[]) try {
  14. locale ru(locale(argc>3 ? argv[3] : ""), new std::codecvt_utf8<wchar_t>);
  15. ios_base::sync_with_stdio(false);
  16.  
  17. wifstream inf;
  18. if (argc>1) inf.open(argv[1]), wcin.rdbuf(inf.rdbuf());
  19. wcin.imbue(ru);
  20.  
  21. wofstream outf;
  22. if (argc>2) outf.open(argv[2]), wcout.rdbuf(outf.rdbuf());
  23. wcout.imbue(ru);
  24.  
  25. unordered_map<wstring, int> dict;
  26. for(wstring s; wcin >> s;) {
  27. transform(begin(s),end(s), begin(s),
  28. [&ru](auto c) { return tolower(c, ru);});
  29. s.erase(remove_if(begin(s),end(s),
  30. [&ru](auto c) { return !isalpha(c, ru);}),
  31. s.end());
  32. if (!s.empty()) --dict[s];
  33. }
  34.  
  35. vector<pair<wstring,int>> result(begin(dict),end(dict));
  36. sort(begin(result),end(result),
  37. [](auto& a, auto& b) {
  38. return tie(a.second,a.first) < tie(b.second,b.first);
  39. });
  40.  
  41. for(auto& i : result) wcout << -i.second << " " << i.first << "\n";
  42. return 0;
  43. } catch(exception& e) { cout << e.what() << endl; }
  44.  
Success #stdin #stdout 0s 17752KB
stdin
Call me Ishmael. Many years later, as he faced the firing squad, Colonel Aureliano Buendía
was to remember that distant afternoon when his father took him to
discover ice. Лолита, свет моей жизни, огонь моих чресел. Грех мой, душа моя, Ло-ли-та Ло. Ли. Та. Она была Ло, просто Ло, по утрам, ростом в пять футов (без двух вершков и в одном носке). Она была Лола в длинных штанах. Она была Долли в школе. Она была Долорес на пунктире бланков. Но в моих объятьях она была всегда: Лолита
stdout
5 была
5 в
5 она
3 ло
3 лолита
2 to
2 моих
1 afternoon
1 as
1 aureliano
1 buendía
1 call
1 colonel
1 discover
1 distant
1 faced
1 father
1 firing
1 he
1 him
1 his
1 ice
1 ishmael
1 later
1 many
1 me
1 remember
1 squad
1 that
1 the
1 took
1 was
1 when
1 years
1 без
1 бланков
1 вершков
1 всегда
1 грех
1 двух
1 длинных
1 долли
1 долорес
1 душа
1 жизни
1 и
1 ли
1 лола
1 моей
1 мой
1 моя
1 на
1 но
1 носке
1 объятьях
1 огонь
1 одном
1 по
1 просто
1 пунктире
1 пять
1 ростом
1 свет
1 та
1 утрам
1 футов
1 чресел
1 школе
1 штанах