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. c#中的math类

    http://wenku.baidu.com/link?url=TliiVtdB8IeO3wiM9mVSD-3wLZcLum7dsXlEZgSKawo6x-qvE_G3VL_yDa3ZQ_9ZFlGG ...

  2. 三层架构dal 层基本代码 非查询/查询

    DAL 数据链路层 非查询/查询 using System;using System.Collections.Generic;using System.Linq;using System.Text;u ...

  3. level分层次输出内容添加leve

    代码如下:function getSubComments($parent = 0, $level = 0) { $db = &JFactory::getDBO(); $sql = " ...

  4. PowerDesigner 15.2入门学习 二

    PowerDesigner中如何生成主键和自增列 1.SQL Server版本: 第一步,首先要建立与数据库的连接,方法较多,这里举个例子: http://www.cnblogs.com/netsql ...

  5. C++11---nullptr

    1.nullprt与NULL 代码: void f(int i) {    cout << "f(int)" << endl;} void f(char* ...

  6. PHP的排序函数的总结

    Sort     破坏索引 升序    值排序 Rsort    破坏索引 降序    值排序 Asort    保持索引 升序     值排序 Arsort   保持索引 降序     值排序 Ks ...

  7. 在eclipse中将SVN项目check下来的正确步骤

    学习下面的方法后再也不用从svncheck到本地后再导入到eclipse里了. 1. 首先Import,在弹出框里选择SVN-从SVN检出项目,然后按照提示一步一步直到选中了目标项目,然后点击next ...

  8. ps aux和ps -ef命令区别

      ps aux 是用BSD的格式来显示 java这个进程 显示的项目有:USER,PID,%CPU,%MEM,VSZ,RSS,TTY,STAT,START,TIME,COMMAND   ps -ef ...

  9. 查看IIS哪个应用程序池占用CPU过高

    1. 进入cmd 2. %systemroot%\system32\inetsrv\AppCmd.exe list wp       这样就能找到活动的应用程序池的PID了 3. 对照资源管理器的PI ...

  10. 委托(delegate)的三种调用方式:同步调用,异步调用,异步回调(转载)

    下面为即将被调用的方法: public delegate int AddHandler(int a,int b); public class 加法类 { public static int Add(i ...