fork download
  1. #include <bits/stdc++.h>
  2. #define yaaameeroooooniiiichaaaaa ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  3. #define el '\n'
  4. #define ll long long
  5. #define ld long double
  6. #define ull unsigned long long
  7. #define f first
  8. #define s second
  9. #define all(a) (a).begin(), (a).end()
  10. #define rall(a) (a).rbegin(), (a).rend()
  11. #define sz(a) (int)(a).size()
  12. #define db(x) cout << (x) << '\n';
  13. #define pb push_back
  14. #define pf push_front
  15. #define ld long double
  16. #define pii pair<ll,ll>
  17. using namespace std;
  18. //#define ordered_set tree < pair<ll, ll> , null_type , less<pair<ll, ll>> ,rb_tree_tag , tree_order_statistics_node_update >
  19. //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  20. #include <ext/pb_ds/assoc_container.hpp>
  21. #include <ext/pb_ds/tree_policy.hpp>
  22. using namespace __gnu_pbds;
  23. template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  24. const ll N = 3e5+5;
  25. const ll mod = 1e16+5;
  26. const int oo = 0x3f3f3f3f;
  27. ///int dx[4] = { -1, 0, 1, 0 };
  28. ///int dy[4] = { 0, 1, 0, -1 };
  29. //int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  30. //int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  31. //int dx[] = {-2,-2,2,2,1,1,-1,-1};
  32. //int dy[] = {-1,1,-1,1,-2,2,-2,2};
  33. string dir="URDL";
  34. map<string,int>ma;
  35. bool compare(pair<int,string> x , pair<int,string> y)
  36. {
  37. if(x.f==y.f){
  38. return x.s>=y.s;
  39. }
  40. }
  41. void levi_ackerman()
  42. {
  43.  
  44. int n ;
  45. cin>>n;
  46. string ss[n];
  47. int cnt=0;
  48. for(int i = 0 ; i<n ; i++)
  49. {
  50. cin>>ss[i];
  51. ma[ss[i]]++;
  52. }
  53. vector<pair<int,string>>v;
  54. for(auto i : ma)
  55. {
  56. v.pb({i.s,i.f});
  57. }
  58. sort(rall(v),compare);
  59. if(sz(v)<5){
  60. for(int i = 0 ; i<sz(v) ; i++){
  61. cout<<v[i].s<< " "<<v[i].f<<el;
  62. }
  63. }
  64. else{
  65. for(int i = 0 ; i<5 ; i++){
  66. cout<<v[i].s<< " "<<v[i].f<<el;
  67. }
  68. }
  69.  
  70. }
  71. int main()
  72. {
  73. yaaameeroooooniiiichaaaaa
  74. int t;
  75. t=1;
  76. //cin>>t;
  77. while(t--)
  78. {
  79. levi_ackerman();
  80. }
  81. }
Success #stdin #stdout 0.01s 5428KB
stdin
Standard input is empty
stdout
Standard output is empty