题解 | #子串计算#

子串计算

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 13:47
机械打工仔:你自己匿名可以,这么好的公司就别给它匿名了
点赞 评论 收藏
分享
07-07 12:47
门头沟学院 Java
码农索隆:竟然还真有卡体检报告的
点赞 评论 收藏
分享
炫哥_:哥们项目描述里面vector和mysql之类的都要写吗,直接开头技术栈巴拉巴拉就行了,完全不是技术点啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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