题目描述 给出一个01字符串(长度不超过100),求其每一个子串出现的次数。 输入描述: 输入包含多行,每行一个字符串。 输出描述: 对每个字符串,输出它所有出现次数在1次以上的子串和这个子串出现的次数,输出按字典序排序。 示例1 输入 复制 10101 输出 复制 0 2 01 2 1 3 10 2 101 2
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
while (cin >> s) {
map<string,int>m;
for(int i=1;i<=s.length();i++){
for(int j=0;j<i;j++){
m[s.substr(j,i-j)]++;//核心
}
}
for(auto it=m.begin();it!=m.end();it++)
{
if(it->second>1)
cout<<it->first<<" "<<it->second<<endl;
}
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100210.html原文链接:https://javaforall.cn