You are viewing a single comment's thread. Return to all comments →
Using a lambda instead, a little bit shorter:
#include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main(int argc, char** argv) { int n; cin >> n; vector<string> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end(), [](const string& a, const string & b) { return a.length() == b.length() ? a < b : a.length() < b.length(); }); copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n")); return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Big Sorting
You are viewing a single comment's thread. Return to all comments →
Using a lambda instead, a little bit shorter: