Advertisement
sajid161

6:3

Jan 3rd, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.     int t;
  5.     cin>>t;
  6.     while(t--)
  7.     {
  8.         string s,s1;
  9.         vector<string>v;
  10.         map<string,int>mp;
  11.         char c;
  12.         cin>>c;
  13.         getline(cin,s);
  14.         s=c+s;
  15.         for(auto u:s)
  16.          {
  17.            if(isspace(u))
  18.            {
  19.               v.push_back(s1);
  20.               s1.clear();
  21.            }
  22.            else
  23.            {
  24.              s1+=u;
  25.            }
  26.          }
  27.          v.push_back(s1);
  28.          for(int i=0;i<v.size();i++)
  29.          {
  30.              mp[v[i]]++;
  31.          }
  32.          string st;
  33.          int ans=0;
  34.          for(auto u:v)
  35.           {
  36.               if(mp[u]>ans)
  37.               {
  38.                   st=u;
  39.                   ans=mp[u];
  40.               }
  41.           }
  42.           cout<<st<<" "<<ans<<endl;
  43.     }
  44.  
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement