四川第七届 C Censor (字符串哈希)
Censor
frog is now a editor to censor so-called sensitive words (敏感词).
She has a long text pp. Her job is relatively simple -- just to find the first occurence of sensitive word ww 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 11 string ww. The second line contains 11string pp.
(1≤length of w,p≤5⋅1061≤length of w,p≤5⋅106, w,pw,p consists of only lowercase letter)
Output
For each test, write 11 string which denotes the censored text.
Sample Input
    abc
    aaabcbc
    b
    bbb
    abc
    abSample Output
    a
    ab
题目大意;就是每组测试数据输入两个字符串;问第二个字符串中把第一个字符串一样的删除,问最后面还剩下什么;并输出;注意字符串删除后还会形成一个新的字符串;
#include<cstdio>
#include<string.h>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<deque>
using namespace std;
#define ll unsigned long long//要用长整型
char a[];
char b[];
ll p[];
ll a131[];
deque<ll>s;
void init()
{//先打表以防超时
a131[]=;
for(ll i=;i<=;i++)
{
a131[i]=a131[i-]*;
}
}
int main()
{
init();
while(~scanf("%s",&a))
{
while(!s.empty()) s.pop_back();
memset(p,,sizeof(p));
scanf("%s",&b);
ll la=strlen(a);
ll lb=strlen(b);
ll ss=;
for(ll i=;i<la;i++)
{//对ss进行哈希
ss=(ss*+a[i]);
}
ll cnt=;
for(ll i=;i<lb;i++)
{
s.push_back(b[i]);
if(s.size()==)
{
p[cnt++]=b[i];
}
else
{
p[cnt]=(p[cnt-]*+b[i]);
cnt++;
}
if(s.size()>=la&&(p[cnt-]-(p[cnt-la-]*a131[la]))==ss)//选择la长度的哈希,要减去之前的
{//一旦发现哈希相同,删除相同字符串
for(ll j=;j<=la;j++)
{
cnt--;
s.pop_back();
}
}
}
while(!s.empty())
{
printf("%c",s.front());
s.pop_front();
}
printf("\n");
}
return ;
}
四川第七届 C Censor (字符串哈希)的更多相关文章
- 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)
		Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ... 
- 四川第七届 I Travel(bfs)
		Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n1,2,…,n. Amo ... 
- 四川第七届 E Rectangle
		Rectangle frog has a piece of paper divided into nn rows and mm columns. Today, she would like to dr ... 
- 山东省第七届ACM省赛------Memory Leak
		Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ... 
- 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
		"波导杯"安徽科技学院第七届程序设计大赛 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time: 2016-0 ... 
- 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
		"波导杯"安徽科技学院第七届程序设计大赛 原文章网页 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time: ... 
- 山东省第七届ACM省赛------Reversed Words
		Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ... 
- 山东省第七届ACM省赛------Triple Nim
		Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ... 
- 山东省第七届ACM省赛------The Binding of Isaac
		The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ... 
随机推荐
- Linux系统LVM分区减容扩容
			Linux系统LVM分区减容扩容 目标:将VolGroup-lv_home缩小到20G,并将剩余的空间添加给VolGroup-lv_root 1.首先查看磁盘使用情况 [root@localhost ... 
- 通过join方法顺序执行多个线程
			方法一:直接用多线程之间的通讯去解决 package com.toov5.test; import javax.imageio.ImageTypeSpecifier; class Res1{ char ... 
- [转载]Spring配置文件详解一:
			原文地址:与base-package="com.xx">Spring配置文件详解一:<context:annotation-config/>与<contex ... 
- webview 最简单的demo
			) { return; } view.loadUrl(url); }} <!--activity_test.xml> <?xml version="1.0" en ... 
- Java 创建线程的两种方法
			Java提供了线程类Thread来创建多线程的程序.其实,创建线程与创建普通的类的对象的操作是一样的,而线程就是Thread类或其子类的实例对象.每个Thread对象描述了一个单独的线程.要产生一个线 ... 
- Overlay网络与物理网络的关系
			编者按:无论是云计算还是SDN都把注意力集中在数据中心网络的建设上,各种解决方案层出不穷,其中以VMware为代表的软件厂商提出Overlay网络方案后,为数据中心网络的发展提出了新的思路.那么Ove ... 
- html5学习笔记(audio)
			来源于<HTML5高级程序设计> audio api <audio controls> controls告诉浏览器显示播放控件 不指定 type 浏览器自解 oggMP3 ty ... 
- DH02-策略模式
			模式简介 面向对象的编程,并不是类越多越好,类的划分是为了封装,但分类的基础是抽象,具有相同属性和功能的对象的抽象集合才是类. 策略模式(Strategy)定义了算法家族,分别封装起来,让他们相互间可 ... 
- ural 2013 Neither shaken nor stirred
			2013. Neither shaken nor stirred Time limit: 1.0 secondMemory limit: 64 MB The ACM ICPC regional con ... 
- 理解WCF(第一部分,有參考他人)
			依舊不廢話 上乾貨! 1.什么是WCF? WCF全名是:WindowsCommunication Foundation ,是一个运行库和一组 API,用于创建在服务与客户端之间发送消息的系统.它使用 ... 
