map无脑过

子串计算

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

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

string str;
map<string, int> tree_map;

int main()
{
    cin >> str;

    for (int i = 0; i < str.size(); ++i)
        for (int j = i; j < str.size(); ++j)
        {
            string t = str.substr(i, j - i + 1);
            tree_map[t]++;
        }
    
    for (auto [u, v] : tree_map)
        if (v > 1)
            cout << u << ' ' << v << endl;
    return 0;
}

全部评论

相关推荐

12-05 18:09
已编辑
广东药科大学 后端工程师
点赞 评论 收藏
分享
双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

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