map实在是太牛逼了!
用到两个东西:
1,map
2,string的substr()函数
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
while(cin>>s){
map<string,int> mp;
for(int i=0;i<=s.length();i++){//i<=s.length注意等号
for(int j=0;j<i;j++){
mp[s.substr(j,i-j)]++;
}
}
for(map<string,int>::iterator it = mp.begin();it!=mp.end();it++){
if(it->second>1)
cout<<it->first<<" "<<it->second<<endl;
}
}
}