题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4438

题意:给出两个字符串A, B,  要求每次将B中第一次出现的A删除, 然后将B剩下的两段前后合并, 然后重复这个过程直到没有可以删除的A位置, 问最后剩下的串是什么

解题思路:链表+kmp,对字符串A做kmp,然后和字符串B进行匹配

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>using namespace std;#define LL long long
const int INF = 0x3f3f3f3f3f;char a[5000010];
char b[5000010];
int nt[5000010];
int nex[5000010];
int p[5000010];
int len1, len2;void getNext()
{nt[0] = -1;for (int i = 0; i < len1; i++){int k=nt[i];while (k>0&&  a[i]!=a[k])k = nt[k];nt[i + 1] = k + 1;}
}int main()
{while (~scanf("%s%s",a,b)){len1 = strlen(a), len2 = strlen(b);if (len1 > len2){printf("%s\n", b);continue;}getNext();for (int i = 0; i <= len2; i++){nex[i] = i + 1;p[i] = i - 1;}for (int i = 0, j = 0; i < len2;){if (j < len1 && b[i] == a[j]) j++;else{while (j >=0&&b[i]!=a[j])j = nt[j];j++;}if (j == len1){int x = i;for (int k = 0; k < len1; k++) i = p[i];if (i == -1){p[nex[x]] = -1;i = nex[x];j = 0;continue;}else{nex[i] = nex[x];p[nex[x]] = i;for (int k = 1;k<len1 ; k++){if (p[i] != -1) i = p[i];else break;}j = 0;}}else i = nex[i];}int cnt=0,k = len2;while (p[k] != -1){a[cnt++] = b[p[k]];k = p[k];}for (int i = cnt - 1; i >= 0; i--) printf("%c", a[i]);printf("\n");}return 0;
}

SCU4438-Censort相关推荐

  1. SCU4438 Censor(审查员) (KMP算法与模拟栈的应用 || HASH表与模拟栈的结合)

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

  2. SCU-4438 Censor(字符串哈希||KMP)

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

  3. Scu4438 栈+哈希

    题目描述 现在给定一个你很讨厌的字符串 A 和另外一个字符串 B,请删除在 B 中出现的所有 A. 请注意:有可能在删除一个 A 后导致新的 A 出现,此时请继续删除,直到没有 A. 输入格式 输入为 ...

  4. SCU4438 Censor(字符串哈希)

    http://acm.scu.edu.cn/soj/problem.action?id=4438 Censor frog is now a editor to censor so-called sen ...

  5. scu4438(KMP)

    题目链接:https://cn.vjudge.net/contest/159024#problem/C 1 #include<cstdio> 2 #include<cstring&g ...

  6. SCU 4438 Censor 字符串hash

    http://fastvj.rainng.com/problem/SCU-4438 题意:一个文本串和模式串,如果文本串中出现了模式串直接删除,然后拼接成一个新串,继续删除.求最后处理过的字符串. 做 ...

最新文章

  1. javacc的源码构建
  2. python秒数转化为时间用户jianpang_Python中文转为拼音
  3. Quartz框架学习(1)—核心层次结构
  4. 对Bootloader(引导加载程序)的几点理解
  5. 中国大学MOOC-数据结构基础习题集、06-3、公路村村通
  6. linux caffe生成的模型,深度学习之pytorch转caffe转ncnn模型转换(三)
  7. Cesium Workshop
  8. 让php来搞定一切!,ubuntu安装和配置php5
  9. Google Pixel 2拍照黑科技:单摄搞定背景虚化+内部潜伏神秘芯片
  10. Amazon Lambda支持以简单队列服务作为事件源了
  11. BSOD 又见BSOD。。。。
  12. python 中的坦克大战0.1版本
  13. 洛谷 P1278 单词游戏 【状压dp】
  14. 计算机课评课的常用语,评课常用语
  15. 华为端到端项目管理流程_从项目流程管理解析华为项目管理
  16. HTML5期末大作业:关于旅游主题网站设计——开心网旅游网页源码(15页) HTML+CSS+JavaScript
  17. Android 7.1 PackageInstaller(应用安装器)增加自动点击安装
  18. 《东周列国志》第二十一回 管夷吾智辨俞儿 齐桓公兵定孤竹
  19. Spring源代码分析(11)---JDBC Dao(老树发新芽)
  20. 主引导扇区(MBR),分区表(DPT)及活动分区(DBR)

热门文章

  1. 字符(Java Char)对应的ASCII码大全(十进制0 ~ 255)
  2. 5G智能水表产业生态大会召开,中国电信5G赋能智慧水务新未来
  3. 【IE设置】【IE ActiveX】IE设置安全规则 【受信任站点设置】
  4. 使用videojs播放m3u8视频监控。
  5. 乐博乐博机器人上课安排_乐博乐博机器人:校管家是学校经营管理的根基
  6. Top 10 torrent sites
  7. 恒生金锐软件面试总结
  8. 合盖计算机后,外接显示器不休眠
  9. vue使用讯飞语音webapi
  10. 学校管理系统(Python)