#include <iostream> #include <cstdio> #include <map> using namespace std; /** * 子串计算--北京大学 * @return */ int main() { string str; while (cin >> str) { map<string, int> countMap; for (int i = 0; i <= str.size(); ++i) { for (int j = 0; j < i; ++j) { /* * 获取所有的子串 * 以子串为key,子串出现的次数为value */ string key = str.substr(j, i - j); /* * 如果key存在,则其值value加1 * 如果key不存在,则其值插入的默认值(例如,value的类型为int,则默认值为0) */ countMap[key]++; } } map<string, int>::iterator it; for (it = countMap.begin(); it != countMap.end(); ++it) { if (it->second >= 2) { /* * it->first: 关键字key * it->second: 值value */ cout << it->first << " " << it->second << endl; } //cout << it->first << " " << it->second << endl; } } return 0; }