Я хочу отсортировать вектор строк сначала по их длине, а затем в алфавитном порядке.
Моя быстрая первоначальная реализация:
#include
#include
#include
#include
using namespace std;
int main() {
vector words {"zzz", "aaazzz", "zz", "a"};
sort(words.begin(), words.end(), [](auto& w1, auto& w2) {
if (w1.length() < w2.length()) {
return true;
}
return w1 < w2;
});
for (auto& w : words) {
cout
Подробнее здесь: https://stackoverflow.com/questions/793 ... ct-results