Censor

frog is now a editor to censor so-called sensitive words (敏感词).

She has a long text pp. Her job is relatively simple -- just to find the first occurence of sensitive word ww and remove it.

frog repeats over and over again. Help her do the tedious work.

Input

The input consists of multiple tests. For each test:

The first line contains 11 string ww. The second line contains 11 string pp.

(1≤length of w,p≤5⋅1061≤length of w,p≤5⋅106, w,pw,p consists of only lowercase letter)

Output

For each test, write 11 string which denotes the censored text.

Sample Input

abc

aaabcbc

b bbb

abc ab

Sample Output

a

ab

// 题意:第一行一个敏感词,然后一行文本,操作如下,删除敏感词,然后如果又新组成敏感词, 重复删掉,直到没有敏感词

//如果用KMP和模拟链表的话,就是如果匹配成功了,用链表删除后,再回退lent长度继续匹配,有点麻烦,貌似还可以hash做

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <string.h>
using namespace std;
const int MX=; int lens,lent;
char T[MX];
char S[MX];
int l[MX];
int r[MX];
int fail[MX]; void getfail()
{
int i,j;
i=,j=;
fail[]=;
while(i<lent)
{
if (j==||T[i]==T[j])
{
i++,j++;
fail[i]=j;
}
else j = fail[j];
}
} void kmp()
{
int i=;
int j=;
while(i<=lens&&j<=lent)
{
if (j==||S[i]==T[j])
{
i=r[i];
j++;
}
else j = fail[j]; if (j>lent)
{
int num=;
int pos=i;
while (num<lent)
{
pos = l[pos];
num++;
}
r [ l[ pos ] ] = i;
l [ i ] = l[ pos ]; num=;
pos=i;
while (num<lent)
{
if (l[pos]==) break;
pos = l[pos];
num++;
}
j=;
i = pos;
}
}
} int main()
{
while(scanf("%s",T+)!=EOF)
{
scanf("%s",S+);
lens = strlen(&S[]);
lent = strlen(&T[]); getfail(); for (int i=;i<=lens+;i++)
{
l[i] = i-;
r[i] = i+;
} kmp();
for (int i = r[];S[i];i = r[i])
{
printf("%c",S[i]);
}
printf("\n");
}
return ;
}

Censor(KMP)的更多相关文章

  1. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  2. SCU 4438 Censor|KMP变形题

    传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...

  3. SCU 4438 Censor KMP/Hash

    题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...

  4. 2015 四川省赛 C Censor(哈希 | KMP)

    模式串为子串 KMP /* @author : victor */ #include <bits/stdc++.h> using namespace std; typedef long l ...

  5. 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈

    [BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...

  6. 2015弱校联盟(1) - C. Censor

    C. Censor Time Limit: 2000ms Memory Limit: 65536KB frog is now a editor to censor so-called sensitiv ...

  7. 『字符串模式匹配 KMP』

    字符串模式匹配 我们要先了解一下问题是什么. 模式匹配是数据结构中字符串的一种基本运算,给定一个子串,要求在某个字符串中找出与该子串相同的所有子串,这就是模式匹配. KMP 然后我们来认识一下今天的主 ...

  8. Censor SCU - 4438

    frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...

  9. SCU 4438:Censor

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...

随机推荐

  1. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何配置虚拟轴 TC2

    右击NC- Configuration,然后Append Task,然后右击Axis,Append Axis   轴的类型可以分为:Continuous Axis,默认的类型,NC可以连续闭环控制该轴 ...

  2. 可伸缩Web架构与分布式系统(2)

    开源软件近年来已变为构建一些大型网站的基础组件.并且伴随着网站的成长,围绕着它们架构的最佳实践和指导准则已经显露.这篇文章旨在涉及一些在设计大型网站时需要考虑的关键问题和一些为达到这些目标所使用的组件 ...

  3. Ios 调用Appstore 下载界面 [[UIApplication sharedApplication] openURL

    http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?mt=8&id=286274367 id = itunesconn ...

  4. 网络编程——The C10K Problem(C10K = connection 10 kilo 问题)。k 表示 kilo,即 1000

    The C10K problem翻译 (C10K = connection 10 kilo 问题).k 表示 kilo,即 1000 比如:kilometer(千米), kilogram(千克). 如 ...

  5. 单用户模式下mount -o remount,rw / 有大用途

    我们的Linux系统在无法启动时候,通常需要进入单用户模式下进行修改一些配置文件,或调整一些参数方可.但是在进入单用户模式后,我们的/文件系统是只读模式,无法进行修改,那么这个时候我们就需要用到一条命 ...

  6. 语言那点事,crt

    C语言标准(不管是ANSI 还是ISO)包含2部分,一部分是语言本身的标准,另一部分是C标准函数库.C标准函数库规定了函数的原型和功能,但是并没限定这些函数要怎么实现.所谓满足标准C规定的C编译器,不 ...

  7. 由于删除DBF文件报错 —— ORA-01033: ORACLE initialization or shutdown in progress

    由于移动或删除DBF文件报错:ORA-01033: ORACLE initialization or shutdown in progress   原因:一般该类故障通常是由于移动文件而影响了数据库日 ...

  8. php文件加载路径

    <?php require('reusable.php'); echo "相对路径加载<br/>"; /* ./ 表示当前文件所在的目录 ../ 表示当前文件所在 ...

  9. 设置U盘启动

    利用快捷键来设置U盘启动,利用快捷键启动相对来说比较简单快捷,推荐大家使用(重要提醒:选择热键前,请先插入U盘) 组装机主板 品牌笔记本 品牌台式机 主板品牌 启动按键 笔记本品牌 启动按键 台式机品 ...

  10. 20180113Go匿名函数和闭包

    最近codereview看到闭包,得学习下 https://studygolang.com/articles/5057 匿名函数:没有函数名的函数 闭包:外部函数定义的内部函数. 闭包给访问外部函数定 ...