Моя быстрая первоначальная реализация:
Код: Выделить всё
#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
Подробнее здесь: [url]https://stackoverflow.com/questions/79334981/why-does-sorting-strings-by-length-give-incorrect-results[/url]
Мобильная версия