题目大意:

3942: [Usaco2015 Feb]Censoring

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 220  Solved: 115
[Submit][Status][Discuss]

Description

Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest issue contains a rather inappropriate article on how to cook the perfect steak, which FJ would rather his cows not see (clearly, the magazine is in need of better editorial oversight).

FJ has taken all of the text from the magazine to create the string S of length at most 10^6 characters. From this, he would like to remove occurrences of a substring T to censor the inappropriate content. To do this, Farmer John finds the _first_ occurrence of T in S and deletes it. He then repeats the process again, deleting the first occurrence of T again, continuing until there are no more occurrences of T in S. Note that the deletion of one occurrence might create a new occurrence of T that didn't exist before.

Please help FJ determine the final contents of S after censoring is complete

有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程。


Input

The first line will contain S. The second line will contain T. The length of T will be at most that of S, and all characters of S and T will be lower-case alphabet characters (in the range a..z).
 

Output

The string S after all deletions are complete. It is guaranteed that S will not become empty during the deletion process.


Sample Input

whatthemomooofun
moo

Sample Output

whatthefun
题解:KMP算法,做的时候用一个堆记录一下就可以了。
 #include<cstring>
#include<cstdio>
#include<cstring>
char t[],s[];
int m,n,top,i,fix;
int z[],next[],f[];
using namespace std;
int main()
{
scanf("%s%s",s+,t+);
m=strlen(s+); n=strlen(t+);
for (fix=,i=; i<=n; i++)
{
while (fix && t[fix+]!=t[i]) fix=next[fix];
if (t[fix+]==t[i]) fix++;
next[i]=fix;
}
for (int i=; i<=m; i++)
{
fix=f[z[top]];
while (fix && t[fix+]!=s[i]) fix=next[fix];
if (t[fix+]==s[i]) fix++; if (fix==n) top-=(n-);
else
f[i]=fix, z[++top]=i;
}
for (int i=; i<=top; i++) printf("%c",s[z[i]]);
}

bzoj3942——2016——3——15的更多相关文章

  1. 2016.8.15上午纪中初中部NOIP普及组比赛

    2016.8.15上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1333 这次比赛不怎么好,因为这套题目我并不是很擅长. 可同学们 ...

  2. 2016.9.15初中部上午NOIP普及组比赛总结

    2016.9.15初中部上午NOIP普及组比赛总结 2016.09.15[初中部 NOIP普及组 ]模拟赛 又翻车了!表示时超和空超很可恨! 进度 比赛:AC+0+0+20=120 改题:AC+80+ ...

  3. macbook pro 2016 2017 15寸 雷电3 外接显卡 epu 简单教程(不修改UEFI)

    雷电3外接显卡效果还不错,但是除了akitio node 其他厂家并不会维护自己的固件来适配新机型,我自己买的mbp 2016 15''就出现了和AORUS Gaming Box 1070不兼容的问题 ...

  4. [位运算] [搜索] [递推优化] [计算几何] TEST 2016.7.15

    NOIP2014 提高组模拟试题 第一试试题 题目概况: 中文题目名称 合理种植 排队 科技节 源程序文件名 plant.pas/.c/.cpp lineup.pas/.c/.cpp scifest. ...

  5. OneZero第四周第五次站立会议(2016.4.15)

    1. 时间: 15:00--15:15  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  6. bzoj1355——2016——3——15

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1355 题目大意: 1355: [Baltic2009]Radio Transmission ...

  7. poj 3641 ——2016——3——15

    传送门:http://poj.org/problem?id=3461 题目大意:给你两个字符串p和s,求出p在s中出现的次数. 题解:这一眼看过去就知道是KMP,作为模板来写是最好不过了.... 这道 ...

  8. 2016.07.15——istringstream测试

    istringstream测试 1.istringstream strcin(str),字符串(str)可以包括多个单词,单词之间使用空格分开 #include "stdafx.h" ...

  9. 2016.5.15——leetcode:Number of 1 Bits ,

    leetcode:Number of 1 Bits 代码均测试通过! 1.Number of 1 Bits 本题收获: 1.Hamming weight:即二进制中1的个数 2.n &= (n ...

随机推荐

  1. Talking about Health

    George: Doctor, what is the best way to stay healthy? Dictor: Having a good diet is probably the mos ...

  2. XML回顾

    xml加强 一.sax解析    1)原理: 读取xml的某个部分,解析一部分(读取一点,解析一点)    2)步骤:         SAXParserFactory factory = SAXPa ...

  3. angular实现select的ng-options

    html <div ng-controller="ngSelect"> <select ng-model="vm.selectVal" ng- ...

  4. JSP文件上传--FileUpload组件

    如果使用上传操作,并且没有使用框架之类,最好使用Smartupload,因为FileUpdate太难使用. 下载组件: fileupload包:http://commons.apache.org/pr ...

  5. cakephp 的事件系统(Getting to grips with CakePHP’s events system), 基于观察者模式

    This article was written about CakePHP 2.x and has been untested with CakePHP 3.x CakePHP seems to g ...

  6. JAVA事件监听机制学习

    //事件监听机制 import java.awt.*; import java.awt.event.*; public class TestEvent { public static void mai ...

  7. pycharm 安装venv的依赖包

    (venv)$ pip install -r requirements.txt

  8. HDU 1166 敌兵布阵(树状数组)

    之前用过了线段树的做法,树状数组的也补上吧 #include<iostream> #include<cstdio> #include<cstring> using ...

  9. Asp.Net MVC以 JSON传值扩展方法

    Asp.Net在客户端和服务器端,以JSON形式相互传值,可写扩展方法,用到的类型如下: DataContractJsonSerializer类: 该类在System.Runtime.Serializ ...

  10. 深入浅出Ajax(四)

    function initPage() { btn.onmouseover = buttonOver; btn.onmouseover = buttonOut; } 如上,浏览器只会运行指定的最后一个 ...