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;
}
}
///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