题解 | #子串计算#

子串计算

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")

全部评论

相关推荐

点赞 评论 收藏
分享
牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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