题解 | #子串计算#

子串计算

https://www.nowcoder.com/practice/bcad754c91a54994be31a239996e7c11

#include <iostream>
#include <map>
using namespace std;

int main() {
    string str;
    while (cin >>str) { 
        map<string,int> number;
        int len=str.size();
        for(int i=0;i<len;i++)//子串开始位置
        {
            for(int j=1;j<=len-i;j++)//子串长度
            {
                string str1=str.substr(i,j);
                number[str1]+=1;
            }
        }

        map<string,int>::iterator it;//传闻中的迭代器
        for(it=number.begin();it!=number.end();it++)//只能用!=
        {
            if(it->second>1)
            cout<<it->first<<" "<<it->second<<endl;
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务