题解 | #子串计算#

子串计算

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

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

map<string ,int> mp;  //定义键值对容器

int main() {
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){  //遍历字符串 (子串头)
        string str;
        for(int j=i;j<n;j++){   //(子串尾)
            str+=s[j]; //子串
            mp[str]++;  //对应的键值对加1
        }
    }

    for(auto t:mp){  //遍历mp
        if(t.second>1){  
            cout<<t.first<<" "<<t.second<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

#子串计算#
全部评论

相关推荐

夏目LTH:这个真的很看运气,多投吧。我从去年十二月底一直投到现在,之前没一个offer,结果两周前投的一家面试官聊的特别好,直接速通offer还给的SP待遇开的比我期望都够。
我的求职进度条
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
03-19 10:38
实力求职者:真的绷不住了,第一张霸总人设,第二张求生欲拉满
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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