Advertisement
momo2345

word with maximum

Jul 29th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. // ********* Assalamualaikum****** IN the name of my Almighty****:):)***
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  5. #define endl "\n"
  6. #define f(i,a,b) for(int i=a;i< b;i++)
  7. #define ff(i,a,b) for(int i= a;i>=b;i--)
  8. #define T int t; cin >>t; while(t--)
  9. #define vi  vector<int>
  10. #define vll vector<long long>
  11. #define vs vector<string>
  12. #define vp vector<pair
  13. #define pii pair<int,int>
  14. #define pb push_back
  15. #define mk make_pair
  16. #define b(a) a.begin(),a.end()
  17. #define rb(a) a.rbegin(),a.rend()
  18. #define I  int
  19. #define ll long long
  20. #define st string
  21. #define C char
  22. #define MN int main()
  23. MN{
  24.    T
  25.    {
  26.        C c;
  27.        cin>>c;
  28.        st s;
  29.        getline(cin,s);
  30.        s=c+s;
  31.        st tmp;
  32.        vs v;
  33.        for(auto u : s){
  34.           if(isspace(u)){
  35.             v.pb(tmp);
  36.           tmp.clear();
  37.        }
  38.        else tmp+=u;
  39.  
  40.    }
  41.       v.pb(tmp);
  42.       map<st,I>cnt;
  43.       I mx=0;
  44.       for(auto u : v){
  45.         cnt[u]++;
  46.         mx=max(mx,cnt[u]);
  47.       }
  48.       st ans;
  49.       for(auto u:v){
  50.         if(cnt[u]==mx){
  51.             ans =u;
  52.             break;
  53.         }
  54.       }
  55.       cout<<ans<<" "<<mx<<endl;
  56. }
  57. }
  58. //*******Happy Coding*******???******
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement