【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 = & ...
随机推荐
- Codeforces 1239D. Catowice City
传送门 如果选择 $i$ 当陪审团成员,那么 $i$ 认识的猫一定不能参加 又因为总人数和猫数要为 $n$ ,那么 $i$ 认识的猫 的主人也一定要当陪审团成员(不然总数不够) 所以可以考虑这样构图, ...
- Redis使用Docker镜像安装
详细见本人以下文档: https://www.cnblogs.com/zyc-blogs/p/9621727.html
- 谈谈Java对象的强引用,软引用,弱引用,虚引用分别是什么
整体结构 java提供了4中引用类型,在垃圾回收的时候,都有自己的各自特点. 为什么要区分这么多引用呢,其实这和Java的GC有密切关系. 强引用(默认支持模式) 把一个对象赋给一个引用变量,这个引用 ...
- Linux设备驱动程序 之 vmalloc
vmalloc()函数的工作方式类似于kmalloc(),只不过在前者分配的内存虚拟地址是连续的,而物理地址则无须连续:这也是用户空间分配函数的工作方式:由malloc()返回的页在进程的虚拟地址空间 ...
- 中国萌兔-月饼工厂流水线 -万圣节萌宠-月饼售罄后续-B站东予薏米
B站(Blibli)up主,东予薏米.下面画的五只兔兔,两只狗狗,一只猫猫都是她家的 啊!有个会画画的主人真是幸福- 蹦迪的那个兔兔头昏脑胀,敷了冰袋和膏药哈哈哈哈,好可爱! 下班了下班了~今天真是太 ...
- Qt pro工程文件介绍
app - 建立一个应用程序的makefile.这是默认值,所以如果模板没有被指定,这个将被使用. lib - 建立一个库的makefile. vcapp - 建立一个应用程序的Visual Stud ...
- mongoose 建立schema 和model
在node中使用MongoDB很多情况下,都是使用mongoose的,所以这集来介绍一下 安装 yarn add mongoose 连接 const mongoose = require(" ...
- Java synchronized和Lock
Synchronized 1. 将synchronized加在方法上, 即可实现对此方法的同步 public synchronized void deposit(float amt) { float ...
- java静态标示符static详解
1.static修饰的变量习惯称为静态变量,static修饰的方法称为静态方法,static修饰的代码块叫做静态代码块. 1)static变量 static变量也称作静态变量,静态变量和非静态变量的区 ...
- 使用IDEA来实现分支代码合并
使用beyond comapre进行分支代码的合并是常用的方法,同时比较2个分支的代码,选择需要和入的代码后再提交即可. 如果是不能使用beyond comapre的情况下,使用IDEA的分支比较功能 ...