The flower(寻找出现m次以上,长度为k的子串)
链接:https://ac.nowcoder.com/acm/contest/3665/B
来源:牛客网
题目描述
输入描述:
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
输入
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的子串)的更多相关文章
- 【LeetCode】1461. 检查一个字符串是否包含所有长度为 K 的二进制子串 Check If a String Contains All Binary Codes of Size K
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计长度为 K 的子串个数 日期 题目地址:https ...
- poj2114 寻找树上存在长度为k点对,树上的分治
寻找树上存在长度为k点对,树上的分治 代码和 这个 差不多 ,改一下判断的就好 #include <iostream> #include <algorithm> #inc ...
- CSU 1660 K-Cycle(dfs判断无向图中是否存在长度为K的环)
题意:给你一个无向图,判断是否存在长度为K的环. 思路:dfs遍历以每一个点为起点是否存在长度为k的环.dfs(now,last,step)中的now表示当前点,last表示上一个访问的 点,step ...
- 删除从第i个位置开始,长度为len的子串
/*字符串采用带头结点的链表存储,设计算法函数void delstring(linkstring s, int i,int len)在字符串s中删除从第i个位置开始,长度为len的子串.*//**** ...
- 字符串s中从第i个位置起取长度为len的子串,函数返回子串链表
/*已知字符串采用带结点的链式存储结构(详见linksrting.h文件),请编写函数linkstring substring(linkstring s,int i,int len),在字符串s中从第 ...
- LCS模板,求长度,并记录子串
//LCS模板,求长度,并记录子串 //亦可使用注释掉的那些代码,但所用空间会变大 #include<iostream> #include<cstring> #include ...
- 给定一个set字符和一个正数k,找出所有该做set它可以由长度构成k该字符串集合 print-all-combinations-of-given-length
// 给定一个set字符和一个正数k,找出所有该做set它可以由长度构成k该字符串集合 /* Input: set[] = {'a', 'b'}, k = 3 Output: aaa aab aba ...
- 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 ...
- hiho#1449 重复旋律6 求长度为k的串最大次数 后缀自动机
题目传送门 题目大意:求长度为k的串的最大次数,把k从1到length的所有答案全部输出. 思路: 这道题放在$SAM$里就是求长度$k$对应的所有$right$集中最大的大小. 我们以$aabab$ ...
随机推荐
- 二十四、JavaScript之取字符串长度
一.代码如下 二.效果如下 <!DOCTYPE html> <html> <meta http-equiv="Content-Type" conten ...
- 一百零三、SAP中常量的定义CONSTANTS
一.代码如下 二.运行效果如下
- python+opencv+dlib瘦脸效果
对实现人脸瘦脸简单功能的一个记录,大概流程如下: 1.使用dlib检测出人脸关键点 2.使用Interactive Image Warping 局部平移算法实现瘦脸 参考:https://blog.c ...
- SciKit-Learn 数据集基本信息
## 保留版权所有,转帖注明出处 章节 SciKit-Learn 加载数据集 SciKit-Learn 数据集基本信息 SciKit-Learn 使用matplotlib可视化数据 SciKit-Le ...
- hdu 1160 上升序列 dp
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- ROS2学习日志:TurtleSim测试日志(基于ROS2 Eloquent Elusor)
TurtleSim测试日志(基于ROS2 Eloquent Elusor) 1.ros2 run 1.1 ros2 run turtlesim turtlesim_node --ros-args -- ...
- Java基础之内省
Java基础之内省 什么是内省 首先,我们要知道什么是内省.按我自己的理解就是在反射的原理上进行封装,来更方便的操作JavaBean JavaBean就是特殊格式的类,其规范为: JavaBean ...
- windows driver 创建线程
VOID ThreadStart(_In_ PVOID StartContext) { PWCHAR str = (PWCHAR)StartContext; MySleep(10);//延时10ms ...
- <mvc:default-servlet-handler />说明
优雅REST风格的资源URL不希望带 .html 或 .do 等后缀.由于早期的Spring MVC不能很好地处理静态资源,所以在web.xml中配置DispatcherServlet的请求映射,往往 ...
- core_cm4.h(129): error: #35: #error directive: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
今天使用 systick 的时候,只使用了头文件 core_cm4.h,结果就报错了,原因是 __FPU_PRESENT 没有定义,这个定义其实在 stm32f4xx.h 里面.所以如果要解决这个错误 ...