题解 | #子串计算#

子串计算

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

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

int main() {
    string line;
    while (cin >> line) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        map<string, int> strMap;
        for (int i = 0; i <= line.size() - 1; i++) {//起点
            for (int j = 1; j <= line.size() - i; j++) {//子串长度
                string str = line.substr(i, j);
                strMap[str]++;
            }
        }
        for(auto it=strMap.begin();it!=strMap.end();it++){
if(it->second>=2) cout<<it->first<<' '<<it->second<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

Java转测开第一人:这种就是饼 把应届当廉价劳动力用完然后丢掉
你觉得今年秋招难吗
点赞 评论 收藏
分享
程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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