fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. auto comp = [](const string & a, const string & b) {
  9. if (a.size() < b.size()) return true;
  10.  
  11. if (a.size() > b.size()) return false;
  12.  
  13. return a < b;
  14. };
  15. set<string, decltype(comp)> S(comp);
  16.  
  17. for (int i = 0; i < 9; ++i) {
  18. string s;
  19. getline(cin, s);
  20. S.insert(s);
  21. }
  22.  
  23. cout << "----\n";
  24.  
  25. for (auto s : S) cout << s << "\n";
  26.  
  27. cout << "----\n";
  28. S.erase(S.begin());
  29.  
  30. for (auto s : S) cout << s << "\n";
  31.  
  32. cout << "----\n";
  33. }
  34.  
Success #stdin #stdout 0s 4292KB
stdin
abc
42354
dffhgceew
4335
fcfvb
78907
nnj
a
kjf

stdout
----
a
abc
kjf
nnj
4335
42354
78907
fcfvb
dffhgceew
----
abc
kjf
nnj
4335
42354
78907
fcfvb
dffhgceew
----