Codeforces 977B Two-gram Solution

Solve in C++:

///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh

#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<string,int>mp;
    string s,s1,st;
    int n,i,f=0;
    while(cin>>n>>s)
    {
        f=0;
        for(i=0; i<n-1; i++)
        {
            s1=s.substr(i,2);
            mp[s1]++;
            
            if(mp[s1]>f)
            {
                st=s1;
                f=mp[s1];
            }
        }
     cout<<st<<endl;
    }

}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.