SCU Censor
Censor
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可以找到模板串,关键是删掉后怎么回溯;
直接记录答案数组,删掉模板串相当于下标-len,这样就能轻松回溯;
比赛时居然傻傻地记录最长已删长度,然后回溯,真是太蠢了。。。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000009
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=5e6+;
const int N=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,dp[maxn],nxt[maxn];
char a[maxn],b[maxn],ret[maxn];
int main()
{
int i,j;
while(~scanf("%s%s",a,b))
{
int len=strlen(a);
nxt[]=j=-;
i=;
while(a[i])
{
while(!(j==-||a[i]==a[j]))j=nxt[j];
nxt[++i]=++j;
}
i=j=k=;
while(b[i])
{
ret[++k]=b[i];
while(!(j==-||b[i]==a[j]))j=nxt[j];
++i,++j;
dp[k]=j;
if(j==len)
{
k-=len;
j=dp[k];
}
}
ret[++k]=;
printf("%s\n",ret+);
}
return ;
}
SCU Censor的更多相关文章
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- SCU 4438 Censor(哈希+模拟栈)
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text \(p\). He ...
- Censor SCU - 4438
frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...
- SCU 4438:Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...
- SCU 4438 Censor|KMP变形题
传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...
- SCU 4438 Censor KMP/Hash
题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...
- SCU 4438 Censor(Hash)题解
题意:找出字符串p中的w串删除,反复操作,直到找不到w,输出这个串 思路:哈希处理前缀和,如果值相同就删掉. 代码: #include<iostream> #include<algo ...
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
- ACM: SCU 4440 Rectangle - 暴力
SCU 4440 Rectangle Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practic ...
随机推荐
- 【Poj3241】Object Clustering
Position: http://poj.org/problem?id=3241 List Poj3241 Object Clustering List Description Knowledge S ...
- bzoj4756
http://www.lydsy.com/JudgeOnline/problem.php?id=4756 水题一枚...但是我写了一个小时...手贱打反查不出来... 就是每次线段树合并,先把自己的儿 ...
- bzoj2648
http://www.lydsy.com/JudgeOnline/problem.php?id=2648 kdtree裸题... 抄板子一边抄对了... 挺好理解的,就是说我们先找出中间的元素,然后小 ...
- 使用adb进行关机(转载)
转自:http://hi.baidu.com/fangqianshu/item/dc52b92d31b2dd1542634a3d 其实进入adb shell,然后执行reboot -p或者直接在命令行 ...
- [Swift通天遁地]六、智能布局-(7)通过Group(组)命令实现对多个视图的统一约束
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 涨知识III - 百度2016校园招聘——移动软件研发工程师
1.列关于线程调度的叙述中,错误的是(). 正确答案 :BE A调用线程的sleep()方法,可以使比当前线程优先级低的线程获得运行机会 B调用线程的yeild()方法,只会使与当前线程相同优先级的线 ...
- CDH5.7Hadoop集群搭建(离线版)
用了一周多的时间终于把CDH版Hadoop部署在了测试环境(部分组件未安装成功),本文将就这个部署过程做个总结. 一.Hadoop版本选择. Hadoop大致可分为Apache Hadoop和第三方发 ...
- Win10中的睡眠、休眠
共同点: 都是节能技术. 异同点: 睡眠: 需要耗电.通过键盘鼠标唤醒.唤醒速度快.将用户正在处理的数据保存到内存中,除内存以外的所有设备都停止供电. 休眠: 不需耗电.通过电源键唤醒.唤醒速度慢.将 ...
- Java系列学习(三)-基础语法
1.关键字 特点:全部小写 2.标识符 (1)就是给类,接口,方法等起名字的字符序列 (2)组成规则: A:英文大小写字母 B:数字 C:$和_ (3)注意事项: A:不能以数字开头 B:不能是jav ...
- RTL Compiler之synthesis flow
1 generic RTL Compiler work flow 2 invoking RTL compiler RTL Compiler is invoked from the operating ...