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 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.