链接: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∣≤105,1≤k≤100)(1 ≤ |S| ≤ 10^5, 1 ≤ k ≤ 100)(1≤∣S∣≤105,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 

输出

flo
low
owe
wer

利用map储存长为k的字符串,暴力计算即可。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const LL MOD=;
const double PI = acos(-);
const double eps =1e-;
#define Bug cout<<"---------------------"<<endl
const int maxn=1e5+;
using namespace std; set<string> st;
map<string,int> mp; int main()
{
#ifdef DEBUG
freopen("sample.txt","r",stdin);
#endif
// ios_base::sync_with_stdio(false);
// cin.tie(NULL); string str;
int k;
cin>>str>>k; if(k<=str.size())
{
for(int i=;i<=str.size()-k;i++)
{
string now=str.substr(i,k);
mp[now]++;
if(mp[now]==) st.insert(now);
}
} cout<<st.size()<<endl;
for(set<string>::iterator it=st.begin();it!=st.end();it++)
cout<<*it<<endl; return ;
}

-

The flower(寻找出现m次以上,长度为k的子串)的更多相关文章

  1. 【LeetCode】1461. 检查一个字符串是否包含所有长度为 K 的二进制子串 Check If a String Contains All Binary Codes of Size K

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计长度为 K 的子串个数 日期 题目地址:https ...

  2. poj2114 寻找树上存在长度为k点对,树上的分治

    寻找树上存在长度为k点对,树上的分治  代码和  这个  差不多 ,改一下判断的就好 #include <iostream> #include <algorithm> #inc ...

  3. CSU 1660 K-Cycle(dfs判断无向图中是否存在长度为K的环)

    题意:给你一个无向图,判断是否存在长度为K的环. 思路:dfs遍历以每一个点为起点是否存在长度为k的环.dfs(now,last,step)中的now表示当前点,last表示上一个访问的 点,step ...

  4. 删除从第i个位置开始,长度为len的子串

    /*字符串采用带头结点的链表存储,设计算法函数void delstring(linkstring s, int i,int len)在字符串s中删除从第i个位置开始,长度为len的子串.*//**** ...

  5. 字符串s中从第i个位置起取长度为len的子串,函数返回子串链表

    /*已知字符串采用带结点的链式存储结构(详见linksrting.h文件),请编写函数linkstring substring(linkstring s,int i,int len),在字符串s中从第 ...

  6. LCS模板,求长度,并记录子串

    //LCS模板,求长度,并记录子串  //亦可使用注释掉的那些代码,但所用空间会变大 #include<iostream> #include<cstring> #include ...

  7. 给定一个set字符和一个正数k,找出所有该做set它可以由长度构成k该字符串集合 print-all-combinations-of-given-length

    // 给定一个set字符和一个正数k,找出所有该做set它可以由长度构成k该字符串集合 /* Input: set[] = {'a', 'b'}, k = 3 Output: aaa aab aba ...

  8. leetcode-219-Contains Duplicate II(使用set来判断长度为k+1的闭区间中有没有重复元素)

    题目描述: Given an array of integers and an integer k, find out whether there are two distinct indices i ...

  9. hiho#1449 重复旋律6 求长度为k的串最大次数 后缀自动机

    题目传送门 题目大意:求长度为k的串的最大次数,把k从1到length的所有答案全部输出. 思路: 这道题放在$SAM$里就是求长度$k$对应的所有$right$集中最大的大小. 我们以$aabab$ ...

随机推荐

  1. cf 763B. Timofey and rectangles

    %%题解,脑洞好大啊. 四色定理什么鬼的..所以一定是yes. 因为矩形边长都是奇数,所以可以按左下角分类,一共4类,分别1,2,3,4就可以了. (需要4种颜色的情况大概就是4个矩形围起来一个矩形) ...

  2. IPsec_crypto[6]次配置

    IPsec_crypto[6]次配置: ①.①:crypto isakmp enbale——启用ISAKMP ②.②:crypto isakmp policy 10——创建一个策略组 ③:encryp ...

  3. POJ 1770 树形DP

    咋一看确实想到的是树形DP,但是我一开始也马上想到环的情况,这样应该是不可以进行树形DP的,然后我自以为是地想用有向图代替无向图,而且总是从能量高的指向能量低的,这样自以为消除了环,但是其实是不对滴, ...

  4. 雷火神山直播超两亿,Web播放器事件监听是怎么实现的?

    Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题,让视音频内容可以不依赖用户安装App,就能进行播放以及在社交平台进行传播.在视频业务大数据平台中,播放数据的统计分析非常重要,所以We ...

  5. MongoDB Projection

    版权所有,未经许可,禁止转载 章节 MongoDB 入门 MongoDB 优势 MongoDB 安装 MongoDB 数据建模 MongoDB 创建数据库 MongoDB 删除数据库 MongoDB ...

  6. HDU - 5591 ZYB's Game(博弈)

    题意:A和B两人在1~N中选数字.已知1<=X<=N,谁先选中X谁就输.每当一个人选出一个不是X的数,裁判都会说明这个数比X大还是小,与此同时,可选范围随之缩小.已知A先选,求满足能让B赢 ...

  7. UVA - 11134 Fabled Rooks(传说中的车)(贪心)

    题意:在n*n的棋盘上放n个车,使得任意两个车不相互攻击,且第i个车在一个给定的矩形Ri之内,不相互攻击是指不同行不同列,无解输出IMPOSSIBLE,否则分别输出第1,2,……,n个车的坐标. 分析 ...

  8. webservice 的简单实现

    1.什么是webservice: 服务端整出一些资源让客户端访问(获取数据) 一个跨语言.跨平台的规范2.作用:跨平台调用.跨语言调用.远程调用 3.什么时候使用webservice: 1.新旧系统之 ...

  9. 澳洲Essay写作常见误区汇总

    近年来,想要不断提升自己开拓视野选择留学的学生越来越多,留学生们对于澳洲essay的写作并不生疏,可是许多人并不能很好地完成澳洲essay的写作,因为留学生们对于澳洲essay写作并不怎么了解.其实, ...

  10. 快速幂(51Nod1046 A^B Mod C)

    快速幂也是比较常用的,原理在下面用代码解释,我们先看题. 51Nod1046 A^B Mod C 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. In ...