题干
c++实现
#include <stdio.h>
#include <string>
#include <map>using namespace std;int main() {char strArr[100];while (scanf("%s", strArr) != EOF) {string str = strArr;map<string, int> subCount;for (int i = 0; i < str.size(); ++i) {for (int j = 1; j <= str.size() - i; ++j) {// i是子串的起始下标,j是子串长度string sub = str.substr(i, j);++subCount[sub];}}//subCount.erase(str);map<string, int>::iterator it;for (it = subCount.begin(); it != subCount.end(); ++it) {if (it->second > 1) {printf("%s %d\n", it->first.c_str(), it->second);}}}return 0;
}