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 ...
随机推荐
- B1277 [HNOI2002]Tinux系统 树形dp
这个题bzoj上没有图,luogu上样例有问题...其实这个题代码不难,但是思考起来还是有一定难度的,其实这些题的重点都在于思考.我就不写了,洛谷上唯一的题解写的挺好,大家可以看一看. 题干: 在do ...
- JSP-Runoob:JSP 动做元素
ylbtech-JSP-Runoob:JSP 动做元素 1.返回顶部 1. JSP 动作元素 与JSP指令元素不同的是,JSP动作元素在请求处理阶段起作用.JSP动作元素是用XML语法写成的. 利用J ...
- shell脚本-循环选择语句
shell脚本-循环选择语句 过程式编程语言: 顺序执行 选择执行 循环执行 注:条件中的变量,可以在执行语句中使用,不用在加上"$". if语句 根据命令的退出状态来执行命令 单 ...
- 【转载】HashMap实现原理浅析
HashMap和Hashtable的区别 两者最主要的区别在于Hashtable是线程安全,而HashMap则非线程安全Hashtable的实现方法里面都添加了synchronized关键字来确保线程 ...
- B. Trees in a Row(cf)
B. Trees in a Row time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- cookie应用(一周内免登陆)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 元素类型以及overflow,white-space等属性
1:预格式化标签:<pre></pre>2:overflow属性="visible/hidden(隐藏)"/scroll/auto(自动)/inherit; ...
- [Swift通天遁地]八、媒体与动画-(4)给相机添加CoreImage滤镜效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 八皇后问题---详解---参考<<紫书>>
在一个8*8的棋盘上 放置八个皇后 , 使得他们互相不攻击(皇后攻击范围为 同行同列同对角线) , 方法一 : 从64个格子中 选一个子集 , 使得 " 子集 中恰好有八个元素 , 且任意 ...
- ASP.NET MVC5 之 AspNetUsers 表增加字段
MVC5 执行数据库迁移时,会生成一些默认的数据表,但是在实际的工作中.若用到的时候,难免要增添一些字段. 1.AspNetUsers 增加字段 A.打开MVC中的 IdentityModels.cs ...