C - Censor SCU - 4438

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 1string 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
#include<bits/stdc++.h>

using namespace std;
const int maxn=5e6+10;

char str[maxn],s[maxn];

struct node{
    char ch;
    int val;
    node(){}
    node(char _ch,int _val):ch(_ch),val(_val){}
};

node stk[maxn];
int top;
int f[maxn];
/*
模式串和文本串的比较
abc
aaabcbabccc
还是比较难受的,当时只是想到了栈这个数据结构,但是没有想到kmp,来匹配
导致匹配一直出现问题,还是做的少啊
*/
void solve(int l1,int l2){
    top=-1;
    int j=0;
    for(int i=0;i<l2;i++){
        if(top==-1)j=0;
        else j=stk[top].val;

        while(j&&str[i]!=s[j])j=f[j];
        if(str[i]==s[j])j++;
        stk[++top]=node(str[i],j);
        if(j==l1){
            top-=l1;
        }
    }
}

void get_f(int l){
    f[0]=f[1]=0;
    for(int i=1;i<l;i++){
        int j=f[i];
        while(j&&s[i]!=s[j])j=f[j];
        f[i+1]=s[i]==s[j]?j+1:0;
    }
}

int main()
{
    while(scanf("%s %s",s,str)==2){
        int len1=strlen(s),len2=strlen(str);
        if(len1>len2){
            printf("%s\n",str);
            continue;
        }
        get_f(len1);
        solve(len1,len2);
        for(int i=0;i<=top;i++)printf("%c",stk[i].ch);
        printf("\n");
    }
    return 0;
}
#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))

#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;


const int maxn=5e6+10;
char str[maxn],p[maxn];

int fail[maxn];

void getFail(char* p,int len){
    fail[0]=fail[1]=0;
    for(int i=1;i<len;i++){
        int j=fail[i];
        while(j&&p[i]!=p[j])j=fail[j];
        fail[i+1]=(p[i]==p[j]?j+1:0);//在J指向i+1的时候,[0,i]文本后缀和模版前缀匹配的长度,也就是J在i+1失配的时候要转移的位置
    }
}

int stk_fail[maxn];
char stk[maxn];
void solve(int len,int m){
    int top=0;
    int j=0;
    stk_fail[0]=0;
    for(int i=0;i<len;i++){
        stk[top]=str[i];//将字符压入栈顶
    
        while(j&&p[j]!=str[i])j=fail[j];
        if(p[j]==str[i])++j;
        stk_fail[++top]=j;
        
        if(j==m){//如果说匹配的长度,已经到了m,说明可以减掉了
            top-=m;
            j=stk_fail[top];
        }
    }
    for(int i=0;i<top;i++)printf("%c",stk[i]);
    printf("\n");
}
/*
abc
aaabcbc
b
bbb
abc
ab
*/
int main()
{
    while(scanf("%s %s",p,str)==2){
        int len=strlen(str),m=strlen(p);
        getFail(p,m);
        solve(len,m);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1 TMS320F2833x,TMS320F2823x DSC .................................................................................. 10 1.1 特性......................................................................................................................... 10 1.2 开始使用.................................................................................................................... 11 2 简介.................................................................................................................................. 12 2.1 引脚分配.................................................................................................................... 14 2.2 信号说明.................................................................................................................... 23 3 功能概述............................................................................................................................ 33 3.1 内存映射.................................................................................................................... 34 3.2 简要说明.................................................................................................................... 41 3.2.1 C28x CPU ....................................................................................................... 41 3.2.2 内存总线(哈弗总线架构) .................................................................................... 41 3.2.3 外设总线......................................................................................................... 41 3.2.4 实时JTAG 和分析.............................................................................................. 42 3.2.5 外部接口(XINTF) ................................................................................................ 42 3.2.6 闪存............................................................................................................... 42 3.2.7 M0,M1 SARAM ............................................................................................... 42 3.2.8 L0, L1, L2, L3, L4, L5, L6, L7SARAM ........................................................................ 43 3.2.9 引导ROM ........................................................................................................ 43 3.2.9.1 引导加载器使用的外设引脚....................................................................... 44 3.2.10 安全性............................................................................................................ 44 3.2.11 外设中断扩展(PIE) 块......................................................................................... 46 3.2.12 外部中断(XINT1-XINT7,XNMI) ............................................................................. 46 3.2.13 振荡器和锁相环(PLL) .......................................................................................... 46 3.2.14 安全装置......................................................................................................... 46 3.2.15 外设时钟......................................................................................................... 46 3.2.16 低功率模式....................................................................................................... 46 3.2.17 外设帧0,1,2,3 (PFn) ...................................................................................... 47 3.2.18 通用输入/输出(GPIO) 复用器................................................................................. 47 3.2.19 32 位CPU 定时器(0,1,2) .................................................................................. 47 3.2.20 控制外设......................................................................................................... 48 3.2.21 串行端口外设.................................................................................................... 48 3.3 寄存器映射................................................................................................................. 49 3.4 器件仿真寄存器............................................................................................................ 51 3.5 中断.......................................................................................................................... 52 3.5.1 外部中断......................................................................................................... 56 3.6 系统控制.................................................................................................................... 57 3.6.1 OSC 和PLL 块.................................................................................................. 58 3.6.1.1 外部基准振荡器时钟选项.......................................................................... 59 3.6.1.2 基于PLL 的时钟模块.............................................................................. 60 3.6.1.3 输入时钟损失....................................................................................... 61

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值