fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long n;
  4. vector<string>v;
  5. vector<string>giamdan;
  6. multiset<string>se;
  7. bool ss(string a,string b)
  8. {
  9. return (a.length()<b.length() || (a.length()==b.length() && a<b));
  10. }
  11. map<string,long long>mp;
  12. bool ss2(string a,string b)
  13. {
  14. return (mp[a]>mp[b] || (mp[a]==mp[b] && a<b));
  15. }
  16. int main()
  17. {
  18. cin>>n;
  19. cin.ignore();
  20. for(int i=0;i<n;i++)
  21. {
  22. string s;
  23. cin>>s;
  24. mp[s]++;
  25. v.push_back(s);
  26. se.insert(s);
  27. }
  28. //yeucau1
  29. for(string x : se)
  30. {
  31. cout<<x<<" ";
  32. giamdan.push_back(x);
  33. }
  34. cout<<endl;
  35. //yeucau2
  36. reverse(giamdan.begin(),giamdan.end());
  37. for(string x : giamdan) cout<<x<<" ";
  38. cout<<endl;
  39. //yeucau3
  40. sort(v.begin(),v.end(),ss);
  41. for(string x : v) cout<<x<<" ";
  42. cout<<endl;
  43. //yeucau4
  44. sort(v.begin(),v.end(),ss2);
  45. for(string x : v) cout<<x<<" ";
  46.  
  47. }
  48.  
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout