fork download
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include<algorithm>
  5. #include<vector>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. // struct comp
  11. // {
  12.  
  13. // bool operator()( std::string lhs, std::string rhs)
  14. // {
  15. // std::transform(lhs.begin(), lhs.end(),lhs.begin(), ::tolower);
  16. // std::transform(rhs.begin(), rhs.end(),rhs.begin(), ::tolower);
  17. // return lhs < rhs;
  18. // }
  19. // };
  20.  
  21. bool char_comp(char lhs, char rhs)
  22. {
  23. char lhs_lower = std::tolower(lhs);
  24. char rhs_lower = std::tolower(rhs);
  25. if (lhs_lower == rhs_lower)
  26. return rhs > lhs;
  27. return lhs_lower < rhs_lower;
  28. }
  29.  
  30. bool string_comp(std::string const & lhs, std::string const & rhs)
  31. {
  32. return std::lexicographical_compare(
  33. lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
  34. char_comp);
  35. }
  36.  
  37.  
  38. int main(){
  39.  
  40.  
  41. std::string str;
  42. std::vector<std::string> v{
  43. "This is a test",
  44. "this is a test",
  45. "Cats",
  46. "cats",
  47. "this thing" };
  48.  
  49.  
  50. std::sort(v.begin(), v.end() , string_comp);
  51.  
  52. for(auto &x: v)
  53. std::cout<<x<<std::endl;
  54. }
  55.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Cats
cats
This is a test
this is a test
this thing