【KMP】Censoring

题目描述

Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest issue contains a rather inappropriate article on how to cook the perfect steak, which FJ would rather his cows not see (clearly, the magazine is in need of better editorial oversight).

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.

输入

The first line will contain S. The second line will contain T. The length of T will be at most that of S, and all characters of S and T will be lower-case alphabet characters (in the range a..z). 

输出

The string S after all deletions are complete. It is guaranteed that S will not become empty during the deletion process. 

样例输入

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的更多相关文章

  1. 【KMP】【最小表示法】NCPC 2014 H clock pictures

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...

  2. 【动态规划】【KMP】HDU 5763 Another Meaning

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...

  3. HDOJ 2203 亲和串 【KMP】

    HDOJ 2203 亲和串 [KMP] Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  4. 【KMP】OKR-Periods of Words

    [KMP]OKR-Periods of Words 题目描述 串是有限个小写字符的序列,特别的,一个空序列也可以是一个串.一个串P是串A的前缀,当且仅当存在串B,使得A=PB.如果P≠A并且P不是一个 ...

  5. 【KMP】Radio Transmission

    问题 L: [KMP]Radio Transmission 题目描述 给你一个字符串,它是由某个字符串不断自我连接形成的.但是这个字符串是不确定的,现在只想知道它的最短长度是多少. 输入 第一行给出字 ...

  6. 【kmp】似乎在梦中见过的样子

    参考博客: BZOJ 3620: 似乎在梦中见过的样子 [KMP]似乎在梦中见过的样子 题目描述 「Madoka,不要相信QB!」伴随着Homura的失望地喊叫,Madoka与QB签订了契约. 这是M ...

  7. 【KMP】BZOJ3942-[Usaco2015 Feb] Censoring

    [题目大意] 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程.输出最后的S串. [思路]三 ...

  8. 【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 ...

  9. 【POJ2406】【KMP】Power Strings

    Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...

随机推荐

  1. vue后台_登录权限

    登录权限控制包含着这么几个方面的含义: 1)不同的权限对应不同的路由 2)侧边栏需要根据不同的权限,异步生成 登录:使用用户名和密码,登录成功后返回用户的token(防止XSS攻击),将此token存 ...

  2. 黑马vue---28、vue中全局过滤器的基本使用

    黑马vue---28.vue中全局过滤器的基本使用 一.总结 一句话总结: vue中的过滤器可以传递参数(根据参数来过滤),也可以用管道符拼接多个过滤器:例如<p>{{ msg | msg ...

  3. 组件 computed 与 vuex 中 getters 的使用,及 mapGetters 的使用,对象上追加属性,合并对象

    vue 是响应式的数据,这一点相当的方便我们的操作,但有些错误的操作方法会 vue 的响应无效 除此之外我们还要了解 vue.set() 和 Object.assgin() 的使用 vue.set() ...

  4. Flutter移动电商实战 --(22)JSON解析和复杂数据模型转换技巧

    json转Model类 创建model文件夹,在里面新建category.dart类 主要根据这个json来分析我们要做成类的样子 { "code": "0", ...

  5. MISS YOU

      文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论

  6. Mac下持续集成-与JMeter与Ant执行后自动发送邮件的整合(性能报告)==

    配置信息如下,其他的为默认的: 添加性能测试报告后,性能测试报告部分构件失败:

  7. Java使用Java OCR API进行验证码识别

    Maven坐标: <!-- https://mvnrepository.com/artifact/com.asprise.ocr/java-ocr-api --> <dependen ...

  8. C语言tips_2 关于scanf 读取规则小结以及与getchar 的区别

    第一点:scanf默认回车和空格是输入不同组之间的间隔和结束符号. 也就是说他不会读取 空格 和 换行符.而是把他们当作一个 数据被读取完成的标志!他的停止标志则为,当%d之类的数据输入结束之后,自动 ...

  9. 【AMAD]django-filter -- 一个通用的,基于用户选择的Django Queryset 过滤系统

    简介 用法 和DRF集成 个人评分 简介 django-filter1可以通过URL的query string参数,动态对Queryset进行过滤. 用法 import django_filters ...

  10. 最新 光环新网java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.优刻得等10家互联网公司的校招Offer,因为某些自身原因最终选择了优刻得.6.7月主要是做系统复习.项目复盘.LeetCo ...