fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <vector>
  5. #include <iterator>
  6. #include <functional>
  7. #include <cctype>
  8.  
  9. template<typename Func>
  10. struct compare
  11. {
  12. bool operator()(const std::string& lhs, const std::string& rhs)
  13. {
  14. std::string lhs_temp(lhs), rhs_temp(rhs);
  15. std::transform(lhs_temp.begin(), lhs_temp.end(), lhs_temp.begin(), tolower);
  16. std::transform(rhs_temp.begin(), rhs_temp.end(), rhs_temp.begin(), tolower);
  17. return Func()(lhs_temp, rhs_temp);
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. setlocale (0, "Russian");
  24. std::vector<std::string> vs = {"Qwerty", "QWERTY", "Медвед","Прэвэд","Медвед","Медвед","Стакан", "ПрЭвЭд",
  25. "Пока","Хой","Медвед","Водка","Хой","Хой","Водка","Стакан", "МЕДВЕД"};
  26.  
  27.  
  28. std::cout<<"Все слова:\n";
  29. std::copy(vs.begin(), vs.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
  30.  
  31. std::cout<<"\nУникальные слова (без учета регистра):\n";
  32. std::sort(vs.begin(), vs.end(), compare<std::less<std::string> >());
  33. std::unique_copy(vs.begin(), vs.end(), std::ostream_iterator<std::string>(std::cout, "\n"), compare<std::equal_to<std::string> >());
  34.  
  35. std::cout<<"\n";
  36. // system("pause");
  37. return 0;
  38. }
Success #stdin #stdout 0s 4496KB
stdin
Standard input is empty
stdout
Все слова:
Qwerty
QWERTY
Медвед
Прэвэд
Медвед
Медвед
Стакан
ПрЭвЭд
Пока
Хой
Медвед
Водка
Хой
Хой
Водка
Стакан
МЕДВЕД

Уникальные слова (без учета регистра):
QWERTY
Водка
МЕДВЕД
Медвед
Пока
ПрЭвЭд
Прэвэд
Стакан
Хой