C. Censor

Time Limit: 2000ms

Memory Limit: 65536KB

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

She has a long text p. Her job is relatively simple – just to find the first occurence of sensitive word w 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 1 string w. The second line contains 1 string p.

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

Output

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

Sample Input

abc

aaabcbc

b

bbb

abc

ab

Sample Output

a

ab

KMP+模拟栈

#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout)
#define VI vector<int>
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int Max = 1e6; char s[Max*5+100]; char c[Max*5+110]; char ans[Max*5+110]; int Next[Max*5+100]; int pre[Max*5+100]; int len1,len2; void Get_Next()
{
int i=0,j=-1;
Next[0]=-1;
while(i<len1)
{
if(j==-1||s[i]==s[j])
{
i++;
j++;
Next[i]=j;
}
else
{
j=Next[j];
}
}
} void Kmp()
{
int k=0;
int j=0;
for(int i=0;i<len2;i++,k++)
{
ans[k]=c[i];
while(j>0&&c[i]!=s[j])
{
j=Next[j];
}
if(c[i]==s[j])
{
j++;
}
if(j==len1)
{
k-=len1;
if(k==-1) j=0;
else j=pre[k]; }
if(k!=-1)
{
pre[k]=j;
}
ans[k+1]=0;
}
ans[k+1]=0;
} int main()
{
while(~scanf("%s %s",&s,&c))
{
len1=strlen(s);
len2=strlen(c);
Get_Next();
Kmp();
printf("%s\n",ans);
}
return 0;
}

2015弱校联盟(1) - C. Censor的更多相关文章

  1. 2015弱校联盟(2) - J. Usoperanto

    J. Usoperanto Time Limit: 8000ms Memory Limit: 256000KB Usoperanto is an artificial spoken language ...

  2. 2015弱校联盟(1) - B. Carries

    B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...

  3. 2015弱校联盟(1) - I. Travel

    I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...

  4. 2015弱校联盟(1) -J. Right turn

    J. Right turn Time Limit: 1000ms Memory Limit: 65536KB frog is trapped in a maze. The maze is infini ...

  5. 2015弱校联盟(1) -A. Easy Math

    A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...

  6. 2015弱校联盟(1) - E. Rectangle

    E. Rectangle Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class name ...

  7. (2016弱校联盟十一专场10.3) D Parentheses

    题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...

  8. (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...

  9. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

随机推荐

  1. HTML 表单和验证事件

    1.表单验证<form></form> (1)非空验证(去空格) (2)对比验证(跟一个值对比) (3)范围验证(根据一个范围进行判断) (4)固定格式验证:电话号码,身份证号 ...

  2. 配置samba服务一例

    问题: 在/data/share目录下建立三个子目录public.training.devel用途如下 public目录用于存放公共数据,如公司的规章制度 training目录用于存放公司的技术培训资 ...

  3. centos install zookeeper cluster

    1.apache官方下载, 2.新版本需要jdk环境,然后配置好jdk环境 3.解压zookeeper,进入解压后的conf,新建zoo.cfg (删掉自带的cfg)内容如下 tickTime=200 ...

  4. IOS第四天(1:图片的方法和缩小,遮罩层)

    @interface HMViewController () @property (nonatomic, strong) UIButton *cover; //阴影 @end @implementat ...

  5. 问题解决(一)在ipad上通过safari浏览文档

    项目背景 针对用Sencha touch 1.1开发的一个用于通过ipad浏览的网站(其实是对PC端一个网站的映射)中的一个模块的开发,这个模块的主要功能就是用户浏览各种‘报告’,这些被阅览的‘报告’ ...

  6. [原创]CI持续集成系统环境---部署gerrit环境完整记录

    开发同事提议在线上部署一套gerrit代码审核环境,不用多说,下面就是自己部署gerrit的操作记录. 提前安装好java环境,mysql环境,nginx环境 测试系统:centos6.5 下载下面三 ...

  7. Shell displays color output

    格式: echo "/033[字背景颜色;字体颜色m字符串/033[控制码" 如果单纯显示字体颜色可以固定控制码位0m. 格式: echo "/033[字背景颜色;字体颜 ...

  8. Spring的RMI远程调用 - (示例)

    一.定义远程服务器上接口 public interface RMIService { public String getInfo(); } 二.实现远程服务器上接口 public class RMIS ...

  9. JS之原型对象

    1.__proto__ 每个对象都有一个__proto__属性,指向该对象的原型对象 <script> var person = function(name,city){ this.nam ...

  10. LeetCode Reconstruct Itinerary

    原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...