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

    abcaaabcbcbbbbabcab

Sample Output

    aab分析:每次删第一个模板串,删掉后重复这个操作,问最后剩下的串;   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+10;
const int N=2e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}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[0]=j=-1;i=0;while(a[i]){while(!(j==-1||a[i]==a[j]))j=nxt[j];nxt[++i]=++j;}i=j=k=0;while(b[i]){ret[++k]=b[i];while(!(j==-1||b[i]==a[j]))j=nxt[j];++i,++j;dp[k]=j;if(j==len){k-=len;j=dp[k];}}ret[++k]=0;printf("%s\n",ret+1);}return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/6791347.html

SCU Censor相关推荐

  1. Censor SCU - 4438 (hash 哈希做法)

    Censor SCU - 4438 题意:给你两串字符串w和p.在p中不停删除w,直到p中没有w.输出此时剩余的字符串. 解题思路: 字符串问题考虑hash做法.先求出字符串w的哈希值.然后遍历字符串 ...

  2. 【哈希-字符串匹配+模拟栈】SCU - 4438: Censor(哈希详解哈哈哈)

    写在前:由于哈希没有好好听讲,也没有下来看.这是排位我开的第一道题,直接string暴力T了.昨天其实就看了哈希,太浮躁,于是本来很简单的哈希愣是没看懂.(于是放弃去看爱5了23333333)今天补上 ...

  3. Censor SCU - 4438 (KMP)

    题目来源: https://vjudge.net/contest/297070#problem/C http://acm.scu.edu.cn/soj/problem.action?id=4438 C ...

  4. ACM: SCU 4438 Censor - KMP

    SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Practice Des ...

  5. SCU - 4438 Censor

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  6. SCU - 4438 Censor

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...

  7. SCU - 4438 Censor (KMP)

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  8. SCU - 4438——Censor(哈希)

    题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4438 题意:给出一个串a和串b,串b中如果有a串则删除,删除后b剩下的串再连到一起,再找串a,反复 ...

  9. C - Censor SCU - 4438

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p. Her jo ...

最新文章

  1. 解决jupyter中无自己创建的虚拟环境
  2. JSP-03-实现数据传递
  3. php 怎么防注入,php 防止注入的几种办法
  4. python安装没有pip选项_python-3.x – 在ubuntu上没有pip的python安装
  5. 分享5个可视化的正则表达式编辑工具
  6. 2012年最后一天,终于盼到公司发报卡了
  7. SAP S/4HANA生产订单抬头字段的维护
  8. Axis通过wsdd部署Web Service
  9. SpringCloud+Redis
  10. 牛客网练习赛26B(简单的dp)
  11. YYKit源码学习——YYMemoryCache
  12. 手机电子词典_论央视主持人的个人修养:习惯性纠正他人读音,手机里装着电子版词典!...
  13. Java中的方法的重载
  14. 联想启天m410进bios_联想启天M410台式机怎么装win7系统
  15. iphone7p配置参数详情_求iPhone7具体参数配置
  16. 面试大厂,你需要掌握这些面试技巧
  17. 【CF487E】Tourists
  18. Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Ecli
  19. 软件中级设计师 - 计算机网络
  20. 元宇宙电商|“NFG”是什么,企业该如何利用元宇宙实现增值呢?

热门文章

  1. 对面试造火箭的一些看法
  2. 9.10诺瓦星云 测开笔试
  3. 大学四年,这个习惯成就了我
  4. VVC学习之环内滤波器(一): Luma Mapping with Chroma Scaling(LMCS)
  5. OTA平台数智化赋能单体酒店,用“轻改造”创“高营收”!
  6. java毕设项目家教平台系统(附源码)
  7. 用Vue实现购物车组件
  8. BlueStacks模拟器:多平台上运行Android应用
  9. Python 爬虫 1. 当当TOP的爬取
  10. Android离线文字转语音(中文)