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+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;
}
时间: 2024-08-07 16:42:54

SCU Censor的相关文章

Censor SCU - 4438

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 w

SCU oj 4438: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 tedio

SCU 4438 Censor

$KMP$,链表. 将$p$弄成链表,每次匹配到,删掉中间的,继续匹配. #include<bits/stdc++.h> using namespace std; const int INF = 0x7FFFFFFF; const int mod = 1e9 + 7; const int N = 5e6 + 10; const int M = 1e4 + 1; const double eps = 1e-10; int T,n,m; char w[N],p[N]; int L[N],R[N],

scu - 3254 - Rain and Fgj(最小点权割)

题意:N个点.M条边(2 <= N <= 1000 , 0 <= M <= 10^5),每一个点有个权值W(0 <= W <= 10^5),现要去除一些点(不能去掉点0),使得结点 0 与结点 N - 1 不连通,求去掉的点的最小权值和. 题目链接:http://cstest.scu.edu.cn/soj/problem.action?id=3254 -->>这是很明显的最小点权割.. 建图方案: 1)将全部点 i 拆成 i 和 i + N.i ->

SCU 2941 I NEED A OFFER!(01背包变形)

I NEED A OFFER!     64bit IO Format: %lld & %llu Submit Status Description Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料, 于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定的申请费用, 这可是很惊人的.Speakless没有多少钱,总共只攒了n万美元.他将在m个学校中选择若干的 (当然要在他的经济承受范围内).每个学校都有不同的申请费用a(万美

SCU 4436 Easy Math 2015年四川省赛题

题目链接:http://acm.scu.edu.cn/soj/problem/4436/ 题意:给你n个整数,求这n个数的平方根和是否是一个整数: 解题思路:如果这题每个数给他算出来,必然费时间,可能还会超精度,所以巧妙的方法就是判断这些整数是否全是完全平方数,如果有一个不是,则他们的平方根和肯定不是一个整数. AC代码: #include <cstdio> #include <cmath> #include <cstring> #include <algorit

SCU 4424(求子集排列数)

A - A Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice SCU 4424 Description Time Limit: 1000ms Description Given N distinct elements, how many permutations we can get from all the possible subset of the eleme

DICOM:基于DCMTK实现C-FIND SCU

背景: 专栏之前写过许多关于DICOM协议的相关文章,有关于概念解析的理论性文章,也有实例演示的应用性文章.目的只有一个,希望能引导大家快速掌握DICOM协议,并着手进行自定义化开发. 目前DICOM协议实现有多种开源库,例如基于C++的DCMTK.基于C#的fo-dicom.基于Java的dcm4che.由于时间关系博文中的相关实例演示经常会穿插着使用三种开源库,因此具体到某一种库可能博文中并未给出示范工程.例如,近期有网友咨询希望利用DCMTK开源库自己动手实现C-FIND查询请求,并对服务

ACM:SCU 4437 Carries - 水题

SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Practice Description Carries frog has nn integers a1,a2,…,ana1,a2,…,an, and she wants to add them pairwise. Unfortunately, frog is somehow afraid of carries (进位). S