Advertisement
chevengur

СПРИНТ № 1 | Лямбда-функции | Урок 2: Компаратор для сортировки 2/3

Sep 21st, 2023
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 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.     int qword = 0;
  10.     std::vector<string>word;
  11.  
  12.     cin >> qword;
  13.  
  14.     for (int i = 0; i < qword; ++i) {
  15.         string words;
  16.         cin >> words;
  17.         word.push_back(words);
  18.     }
  19.    
  20.     std::sort(word.begin(), word.end(), [](string& c1, string& c2) {
  21.         return lexicographical_compare(
  22.             c1.begin(), c1.end(),
  23.             c2.begin(), c2.end(),
  24.             [](char w, char w2) {
  25.             return tolower(w) < tolower(w2);
  26.             });
  27.         });
  28.  
  29.     for (const auto& l : word) {
  30.         std::cout << l << " ";
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement