2015弱校联盟(1) - C. Censor
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的更多相关文章
- 2015弱校联盟(2) - J. Usoperanto
J. Usoperanto Time Limit: 8000ms Memory Limit: 256000KB Usoperanto is an artificial spoken language ...
- 2015弱校联盟(1) - B. Carries
B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
- 2015弱校联盟(1) -J. Right turn
J. Right turn Time Limit: 1000ms Memory Limit: 65536KB frog is trapped in a maze. The maze is infini ...
- 2015弱校联盟(1) -A. Easy Math
A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...
- 2015弱校联盟(1) - E. Rectangle
E. Rectangle Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class name ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) B.Help the Princess!
题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
随机推荐
- bootstrap使用性能问题
1.如icheckbox等的初始化,不要采用类似for in的循环来对所需应用的元素进行初始化,直接采用如 $('[data-toggle="popover"]').popove ...
- HTTP协议 (二) 基本认证
HTTP协议 (二) 基本认证 http协议是无状态的, 浏览器和web服务器之间可以通过cookie来身份识别. 桌面应用程序(比如新浪桌面客户端, skydrive客户端)跟Web服务器之间是如何 ...
- AFN----AFNetworking
一.介绍 官方介绍: 1.适用于iOS和Mac OS X两个平台的网络库 2.基于Foundation URL Loading System上进行一套封装 3.提供了丰富的API接口 4.是一个轻量级 ...
- Vue 双向数据绑定原理分析 以及 Object.defineproperty语法
第三方精简版实现 https://github.com/luobotang/simply-vue Object.defineProperty 学习,打开控制台分别输入以下内容调试结果 userInfo ...
- VB鼠标指针
vbDefault 0 (缺省值)形状由对象决定. VbArrow 1 箭头. VbCrosshair 2 十字线(crosshair 指针). VbIbeam 3 I 型 VbIconPointer ...
- Leetcode | Find Minimum in Rotated Sorted Array I && II
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- 使用beanUtils操纵javabean
Sun公司的内省API过于繁琐,所以Apache组织结合很多实际开发中的应用场景开发了一套简单.易用的API操作Bean的属性——BeanUtils,在Beanutil中可以直接进行类型的自动转换. ...
- Apache Spark技术实战之3 -- Spark Cassandra Connector的安装和使用
欢迎转载,转载请注明出处,徽沪一郎. 概要 前提 假设当前已经安装好如下软件 jdk sbt git scala 安装cassandra 以archlinux为例,使用如下指令来安装cassandra ...
- python中多进程(multiprocessing)
一.multiprocessing中使用子进程概念 from multiprocessing import Process 可以通过Process来构造一个子进程 p = Process(target ...
- ASP.NET获取工程根目录的方法集合
1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory //取得或设置当前工作目录的完整限定路径 方法2.AppDomain.CurrentDomain. ...