【KMP】Censoring
【KMP】Censoring
题目描述
FJ has taken all of the text from the magazine to create the string S of length at most 10^6 characters. From this, he would like to remove occurrences of a substring T to censor the inappropriate content. To do this, Farmer John finds the _first_ occurrence of T in S and deletes it. He then repeats the process again, deleting the first occurrence of T again, continuing until there are no more occurrences of T in S. Note that the deletion of one occurrence might create a new occurrence of T that didn't exist before.
Please help FJ determine the final contents of S after censoring is complete.
输入
输出
样例输入
whatthemomooofun
moo
样例输出
whatthefun
参考博客:
Censoring(栈+KMP)
【题解】:
正常匹配,不过是加了一个栈来维护。
【代码】:
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1e6 + ;
char s[N],p[N],ans[N];
int n,m,top,Next[N],f[N]; void get_Next(){
for(int i=,j= ; i<=m ; i++ ){
while ( j && p[i] != p[j+] ) j = Next[j] ;
if( p[i] == p[j+] ) j++;
Next[i] = j ;
}
}
void Kmp(){ //if( !(m == 1 && s[1] == p[1]) )
//ans[++top] = s[1];
for(int i=,j= ; i<=n ; i++){
ans[++top] = s[i] ;
while ( j && ( j==m || s[i] != p[j+]) ) j = Next[j] ;
if ( s[i] == p[j+] ) j++ ; f[top] = j ;
if( j == m ){
top = top - m ;
j = f[top];
}
}
ans[++top] = '\0';
printf("%s\n",ans+);
}
int main()
{
scanf("%s%s",s+,p+);
n = strlen ( s+ ) ;
m = strlen ( p+ ) ; get_Next();
Kmp();
return ;
}
/*
whatthemomooofun
moo
*/
【KMP】Censoring的更多相关文章
- 【KMP】【最小表示法】NCPC 2014 H clock pictures
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...
- 【动态规划】【KMP】HDU 5763 Another Meaning
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...
- HDOJ 2203 亲和串 【KMP】
HDOJ 2203 亲和串 [KMP] Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【KMP】OKR-Periods of Words
[KMP]OKR-Periods of Words 题目描述 串是有限个小写字符的序列,特别的,一个空序列也可以是一个串.一个串P是串A的前缀,当且仅当存在串B,使得A=PB.如果P≠A并且P不是一个 ...
- 【KMP】Radio Transmission
问题 L: [KMP]Radio Transmission 题目描述 给你一个字符串,它是由某个字符串不断自我连接形成的.但是这个字符串是不确定的,现在只想知道它的最短长度是多少. 输入 第一行给出字 ...
- 【kmp】似乎在梦中见过的样子
参考博客: BZOJ 3620: 似乎在梦中见过的样子 [KMP]似乎在梦中见过的样子 题目描述 「Madoka,不要相信QB!」伴随着Homura的失望地喊叫,Madoka与QB签订了契约. 这是M ...
- 【KMP】BZOJ3942-[Usaco2015 Feb] Censoring
[题目大意] 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程.输出最后的S串. [思路]三 ...
- 【POJ2752】【KMP】Seek the Name, Seek the Fame
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- 【POJ2406】【KMP】Power Strings
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
随机推荐
- spring boot + swagger2
spring boot集成swagger2: swagger2是一个基于restful的开源设计,构建,文档,访问的开源工具集.开发中它的在线可视化文档功能,可以动态生成文档,简化前后对接工作 ...
- 应用fluent二维单向流泥沙冲刷作用下河床变形代码【转载】
本代码转载自:http://www.codeforge.cn/read/260028/keti_2d_b.c__html #include "udf.h" #define Rho ...
- Node.js中npm常用命令大全
npm是什么 NPM的全称是Node Package Manager,是随同NodeJS一起安装的包管理和分发工具,它很方便让JavaScript开发者下载.安装.上传以及管理已经安装的包. npm ...
- dd 命令
dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:b=512:c=1:k=1024:w=2 参数注释: if=文件名:输入文件名 ...
- [转][echarts]地图轮播
代码片断: 来自:https://blog.csdn.net/qq_36947128/article/details/90899564 function Play(){ chart.dispatchA ...
- Python之操作RabbitMQ
RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue, 消息队列(MQ)是一种应用程序 ...
- SaaS领域如何分析收入增长?
SaaS领域如何分析收入增长? 今天我们试着将其模式运用到收入增长上进行分析.这对常规收入的计算会极有帮助,例如企业级应用软件(SaaS)或消费者订阅业务. 列举某公司通过月度订阅获得营收为例,为了更 ...
- React Native使用NetInfo对当前系统网络的判断
有网状态: 断网状态: 代码如下: 注意:第一次参考了http://www.hangge.com/blog/cache/detail_1614.html代码,一直显示的是unknow状态... 最后处 ...
- LODOP设置纸张无效问题
有的打印机不支持自定义纸张,或不支持当前设置的纸张尺寸,会造成纸张尺寸和代码里设置的尺寸不一致的情况.现象:1.代码一样,纸张语句设置正确,有的打印机纸张正常,有的打印机不正常.2.代码一样,纸张语句 ...
- 【c++基础】二进制格式输出char类型
前言 使用CAN通信时将信号转换为char类型进行传输,要查看传输的信息是否正确需要将char类型数据以二进制格式输出: code #include <iostream> int main ...