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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.