F.cpp 415 B

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