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> ...
随机推荐
- bzoj1832: [AHOI2008]聚会--LCA
本来觉得这是一道挺水的题目,后来觉得出题人挺变态的= = 半个小时敲完后,内存超限它给我看TLE,还是0ms,后来才发现内存限制64m 然后卡了一个小时后AC了.. 题目大意是在一棵树上找三点的最短路 ...
- linux卸载mysql,apache,php
卸载Mysql 1.查找以前是否装有mysql 命令:rpm -qa|grep -i mysql 可以看到mysql的包: mysql-3.23.58-9php-mysql-4.3.4-11mod_a ...
- 手动给控制器添加xib
UIViewController绑定xib界面可视化,有两种方式: 1.第一种(自动化),在创建控制器时,勾选xib选项. 2.第二种手动创建一个Xib,然后再手动绑定到对应的控制器上
- IOS第12天(3,UIViewController的生命周期)
#import "HMViewController.h" @interface HMViewController () @property(nonatomic,strong)NSA ...
- 网页FLASH幻灯片播放带链接源代码 pixviewer.swf使用(转)
<script type="text/javascript"> <!-- var focus_width=360 var focus_height=270 ...
- ios-获取商店已上线app信息
NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@ ...
- [转]手机浏览器的User-Agent汇总
手机浏览器的User-Agent汇总 之前介绍的 更简洁的方式修改Chrome的User Agent,轻松体验移动版网络这种简洁的方法好像只适用于Chrome, Chrome不只是浏览界面简洁,对应的 ...
- CentOS7配置日志(VirtualBox)
版本为CentOS-Minimal 1.VirtualBox下安装CentOS. 新建虚拟机 下载CentOS,放入盘片,启动虚拟机,按提示开始安装(建议内存1G,硬盘10G以上) 2. 设置网络 ...
- C#Web异步操作封装
using System; using System.Collections.Generic; using System.Web; namespace HttpAsync { /// <summ ...
- iOS沙盒目录
出于安全考虑,iOS系统的沙盒机制规定每个应用都只能访问当前沙盒目录下面的文件(也有例外,比如系统通讯录能在用户授权的情况下被第三方应用访问),这个规则把iOS系统的封闭性展现的淋漓尽致. 一.沙盒中 ...