fork(10) download
  1. #include <algorithm>
  2. #include <cctype>
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. vector<string> foo = {"Jonathan", "antenna", "jupiter", "Mee", "jOn"};
  11.  
  12. sort(foo.begin(), foo.end(), [](const auto& lhs, const auto& rhs){
  13. const auto result = mismatch(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), [](const auto& lhs, const auto& rhs){return tolower(lhs) == tolower(rhs);});
  14.  
  15. return result.second != rhs.cend() && (result.first == lhs.cend() || tolower(*result.first) < tolower(*result.second));
  16. });
  17.  
  18. for(auto& i : foo) {
  19. cout << i << endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
antenna
jOn
Jonathan
jupiter
Mee