题解 | #子串计算#
子串计算
http://www.nowcoder.com/practice/bcad754c91a54994be31a239996e7c11
寻找子串时,采用暴力搜索
//该题处理子串时采用暴力搜索
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string, int> mp; //sub string ---> number
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
for (int j = i+1; j <= s.size(); j++) {
string key = s.substr(i, j-i);
mp[key]++;
}
}
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second > 1) {
cout << it->first << " " << it->second << endl;
}
}
return 0;
}