题解 | 子串计算

子串计算

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

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
    string str;
    while (cin >> str) { // 注意 while 处理多个 case
        map<string,int> count;
        int lengt=str.size();
        for(int i=0;i<lengt;i++)
           for(int j=i;j<lengt;j++)
           {
            string st=str.substr(i,j-i+1);
            count[st]++;
           }
           for(auto it=count.begin();it!=count.end();it++)
           { if(it->second>1)
            cout<<it->first<<" "<<it->second<<endl;
           }
           

    }
}
// 64 位输出请用 printf("%lld")

很好的用map处理字串的思路

for(int i=0;i<lengt;i++)

for(int j=i;j<lengt;j++)

{

string st=str.substr(i,j-i+1);

count[st]++;

}

全部评论

相关推荐

点赞 评论 收藏
分享
03-29 18:59
运城学院 Java
程序员小白条:咱们要对自己的简历和学历有清晰的认知,不要动不动就大厂了....都26届了,没实习还想着大厂,唉
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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