美文网首页
CodeFoeces-977B

CodeFoeces-977B

作者: ss5smi | 来源:发表于2018-05-08 09:44 被阅读0次

题目

原题链接:Two-gram

题意

在所给字符串中找到出现次数最多的二位字符串,次数相同可随意输出。

代码

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,maxx=0;
    string s,ans;
    map<string,int> m;
    cin>>n>>s;
    for(int i=0; i<n-1; i++) {
        string tmp = s.substr(i,2);
        m[tmp]+=1;
        if(m[tmp]>maxx){
            maxx=m[tmp];
            ans=tmp;
        }
    }
    cout<<ans<<endl;
    return 0;
}

相关文章

  • CodeFoeces-977B

    题目 原题链接:Two-gram 题意 在所给字符串中找到出现次数最多的二位字符串,次数相同可随意输出。 代码

网友评论

      本文标题:CodeFoeces-977B

      本文链接:https://www.haomeiwen.com/subject/mqqvrftx.html