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> ...
随机推荐
- 使用redis的五个注意事项
http://blog.nosqlfan.com/html/3705.html 下面内容来源于Quora上的一个提问,问题是使用Redis需要避免的五个问题.而回答中超出了五个问题的范畴,描述了五个使 ...
- bzoj4517: [Sdoi2016]排列计数--数学+拓展欧几里得
这道题是数学题,由题目可知,m个稳定数的取法是Cnm 然后剩下n-m本书,由于编号为i的书不能放在i位置,因此其方法数应由错排公式决定,即D(n-m) 错排公式:D[i]=(i-1)*(D[i-1]+ ...
- Android SDK 镜像站
Android SDK镜像的介绍使用 http://www.androiddevtools.cn 镜像站地址 由于一些原因,Google相关很多服务都无法访问,所以在很多时候我们SDK也无法升级 ...
- 设置mariadb字符集为utf8
我用的是10.0.25 mariadb, 在centos7系统上,用以下指令设置数据库字符集. [client] default-character-set=utf8 [mysql] defa ...
- Windows内核 基本数据结构
驱动对象: 每个驱动程序都会有唯一的驱动对象与之对应,并且这个驱动对象是在驱动加载时被内核中的对象管理程序所创建的.驱动对象用DRIVER_OBJECT数据结构表示,它作为驱动的一个实例被内核加载,并 ...
- 自己用node.js 搭建APP服务器,然后用AFNetworking 请求 报如下错误:App TransportSecurity has blocked a cleartext HTTP (http://) resource load since it isinsecure. Temporary exceptions can be configured via your app's Info.
"App TransportSecurity has blocked a cleartext HTTP (http://) resource load since it isinsecure ...
- 【转】Unity中的协同程序-使用Promise进行封装(二)
原文:http://gad.qq.com/program/translateview/7170970 译者:王磊(未来的未来) 审校:崔国军(飞扬971) 在上一篇文章中,我们的注意力主要是 ...
- 基于TCP/IP的长连接和短连接
1. TCP连接 当网络通信时采用TCP协议时,在真正的读写操作之前,server与client之间必须建立一个连接,当读写操作完成后,双方不再需要这个连接时它们可以释放这个连接,连接的建立是需要三次 ...
- MVC传递Model
@using System.Configuration;@using System.Text.RegularExpressions;@model Model.NewInfo // 指定Module的 ...
- KVC浅析和实例
KVC 与 KVO 是 Objective C 的关键概念,个人认为必须理解的东西,下面是实例讲解. Key-Value Coding (KVC) KVC,即是指 NSKeyValueCoding,一 ...