链接:https://ac.nowcoder.com/acm/contest/3665/B
来源:牛客网
Every problem maker has a flower in their heart out of love for ACM. As a famous problem maker, hery also has a flower.
Hery define string T as flower-string if T appears more than twice in string S and |T| = k. Hery wants you to find how many flower-string in S.
输入描述:
The first line contains a string S consist of ’f’, ’l’, ’o’, ’w’, ’e’, ’r’ and an integer k.
(1 ≤ |S| ≤ 10^5
, 1 ≤ k ≤ 100
)(1≤∣S∣≤10
5
,1≤k≤100)
输出描述:
Output an integer m in the first line, the number of flower − string in S.
Next m lines, each line contains a flower-string and the lexicographical order of them should be from small to large
示例1
输入
复制
flowerflowerflower 3
输出
复制
4
flo
low
owe
wer`
#include<bits/stdc++.h>
using namespace std;
vector<string> p;
set<string> q;
map<string,int> w;
int main() {
string s;
cin>>s;
int k;
scanf("%d",&k);
if(k>s.length()) {
puts("0");
return 0;
}
for(int i=0;i<=s.length()-k;i++) {
string z=s.substr(i,k);
w[z]++;
if(w[z]>=3) {
if(!q.count(z)) {
p.push_back(z);/*不知道set怎么输出,所以用set的count的函数来将答案写入vector*/
q.insert(z);
}
}
}
sort(p.begin(),p.end());
printf("%d\n",p.size());
for(int i=0;i<p.size();i++)
cout<<p[i]<<endl;/*vector可以用数组的方式输出*/
return 0;
}