//map去重,且map按照key从小到大排序 #include "stdio.h" #include "map" #include "string" using namespace std; int main(){ char buf[110];map<string,int> myMap; while (scanf("%s",buf)!=EOF){ myMap.clear(); string str = buf; int len = 1; while (len <= str.size()){ for (int i = 0; i < str.size()-len+1; ++i) { string s = str.substr(i,len);//按照长度排序 myMap[s]++;//去重,且相同的自增 } ++len; } map<string,int>::iterator it; for (it = myMap.begin(); it != myMap.end(); ++it) { if(it->second > 1) printf("%s %d\n",it->first.c_str(),it->second); } for (int i = 0; i < 110; ++i) { buf[i] = '\0'; } } }