shushus

Спринт 1. Компаратор для сортировки. Задание 2.

Dec 3rd, 2022
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     // считайте входные данные и сформируйте вывод программы
  10.     // ...
  11.     int amount;
  12.     cin>>amount;
  13.     string s;
  14.     vector<string> words;
  15.     for (int i = 0; i<amount; ++i){
  16.         cin>>s;
  17.         words.push_back(s);
  18.     }
  19.    
  20.     sort(words.begin(), words.end(), [] (const string& lha, const string& rha){
  21.         return lexicographical_compare(lha.begin(), lha.end(), rha.begin(), rha.end(),
  22.         [](const unsigned char lhs, const unsigned char rhs){
  23.             return tolower(lhs) < tolower(rhs);
  24.         });
  25.     });
  26.    
  27.     for(auto& word: words){
  28.         cout<<word<<" ";
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment