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$ ...
随机推荐
- 2. FTP 服务器安装
vsftp 安装(linux) Linux : 安装,创建虚拟用户,配置,防火墙设置 1. 安装 执行yum -y install vsftpd 注意: (1) 是否使用sudo权限执行请根据您具体环 ...
- SignalR实现页面实时监控
1.页面截图
- 掌握这几点,轻松搞定Essay Cohesion写作
Cohesion就是衔接,是留学生Essay写作中中一个很重要的评价标准.很多留学生在平时Essay写作中,主体段已经做到了有观点.有例子,字数也不差,但总是被评价为展开不够.说理不清.不好follo ...
- Flink 复杂事物处理
简介 FlinkCEP是在Flink之上实现的复杂事件处理(CEP)库. 它允许你在无界的事件流中检测事件模式,让你有机会掌握数据中重要的事项. Flink CEP 首先需要用户创建定义一个个patt ...
- vue全家桶router、vuex、axios
main.js import Vue from 'vue' import App from './App' import router from './router' import store fro ...
- 吴裕雄--天生自然C++语言学习笔记:C++ 重载运算符和重载函数
C++ 允许在同一作用域中的某个函数和运算符指定多个定义,分别称为函数重载和运算符重载. 重载声明是指一个与之前已经在该作用域内声明过的函数或方法具有相同名称的声明,但是它们的参数列表和定义(实现)不 ...
- Linux运维命令笔记一
1.Centos 无netstat 命令 yum -y install net-toolnetstat -tunp 2.Centos防火墙 systemctl stop firewalld.ser ...
- Newtonsoft.Json版本冲突
如果项目中不同第三方类库分别使用了不同版本的Newtonsoft.Json,可以在配置文件中添加以下节点,将0.0.0.0-9.0.0.0此区间的Newtonsoft.Json使用全部强制指向到项目中 ...
- c++程序—三目运算符
#include<iostream> using namespace std; #include<string> int main() { //三目运算符 ; ; ; c = ...
- Python量化交易的简单介绍
Python只是一门技术. 一.量化交易的发展 1.国外量化金融领域发展日趋成熟. 2.近几年量化交易在国内掀起热潮. 3.Python作为量化交易的编译语言. 二.什么是量化交易 1.利用计算机强大 ...