四川第七届 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
ab
Sample 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 ...
随机推荐
- vRA7 Business error “Untrusted certificate chain”
报错截图: 服务无法注册 第一步:登录vRB 5480页面,取消到vRA的注册 第二部:SSH登录到VRB中,查看bio-ssl.keystore.password. cat /shared/cata ...
- 【P3522】TEM(单调队列+DP)
这个题,题目很长,然而亲爱的翻译已经帮你读完题了,一句话题意. 要求不下降的最长,那么这一段肯定满足队首的左区间不大于队尾的右区间,单调队列容易求解. #include<iostream> ...
- mac下安装py第三方库到python3下
python3 -m pip install **** 中间可能碰到超时问题 python3 pip --default-timeout=100 install -U **** 设置默认超时时间即可 ...
- springboot 配置过滤器
能配置例外 先写配置文件类 FilterConfig.java package com.ty.tyzxtj.config; import javax.servlet.Filter; import or ...
- EntityFramework 学习 一 Multiple Diagrams in Entity Framework 5.0
Visual Studio 2012 provides a facility to split the design time visual representation of the Entity ...
- excel比较筛选两列不一样的数据
在excel表中,罗列两列数据,用B列数据与A列比较,筛选出B列中哪些数据不同,并用红色标记出来. 首先选中B列.直接鼠标左键点击B列即可选中."开始"--->&qu ...
- JDK与JRE及其在Eclipse中的使用
转载自:http://blog.csdn.net/gx1058742912/article/details/51033942 JDK与jRE的区别 JDK(java development kit): ...
- 开启 cmd cmder 代理
win10安装了ShadowSocks软件,浏览器通过代理后就可以***,但有时候需要通过cmd科学下载安装一些组件,就需要设置一下cmd的代理 cmd如果要设置代理的话,需要在执行其他命令之前,先执 ...
- 在其他平台上使用 ActiveMQ
这一章讲了使用其他编程语言来访问 ActiveMQ,其他语言基本上都有相应的协议实现,所以说实现了协议,编程语言不是障碍! 还说了 ActiveMQ 提供了 RESTFul API 和 Ajax AP ...
- Linux系统调用分析
在HelloWorld程序中,我们可以调用libc中的getpid函数获取当前进程的进程号.HelloWorld是运行在用户空间,那么它是如何通过系统调用切换到内核空间来获取PID的呢?原来,在uni ...