F.cpp 484 B

123456789101112131415161718192021222324
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool cmp(const string & a, const string & b) {
  4. if (a.size() != b.size()) {
  5. return a.size() < b.size();
  6. }
  7. return a < b;
  8. }
  9. int main()
  10. {
  11. int n;
  12. while (cin >> n)
  13. {
  14. vector < string > v(n);
  15. for (int i = 0; i < n; i++) {
  16. cin >> v[i];
  17. }
  18. sort(v.begin(), v.end(), cmp);
  19. for (int i = 0; i < n; i++) {
  20. cout << v[i] << endl;
  21. }
  22. }
  23. return 0;
  24. }