题解 | #子串计算#
子串计算
http://www.nowcoder.com/practice/bcad754c91a54994be31a239996e7c11
#include<string>
#include<map>
using namespace std;
int main()
{
string s;
cin >> s;
map<string, int> m; //构建散列表
for (int i = 0; i < s.size(); i++)
{
for (int j = 0; j <= i; j++)
{
m[s.substr(j, i-j+1)]++;
}
}
map<string, int>::iterator it; //定义迭代器
for (it = m.begin(); it != m.end(); it++)
{
if(it->second > 1)
cout << it->first << " " << it->second << endl;
}
return 0;
}