题解 | #子串计算#

子串计算

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

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

int main() {
    string str;
    while(cin >> str){
        map<string, int> number;
        for(int i = 0; i < str.size(); i ++)
            for(int j = 1; i + j <= str.size(); j ++){
                number[str.substr(i, j)] ++;
            }
        
        for(auto t : number){
            if(t.second > 1)
                cout << t.first << " " << t.second << endl;
        }
    }

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

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务