四川第七届 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 ...
随机推荐
- SYN blood攻击
SYN Flood (SYN洪水) 是种典型的DoS (Denial of Service,拒绝服务) 攻击.效果就是服务器TCP连接资源耗尽,停止响应正常的TCP连接请求. 说到原理,还得从TCP如 ...
- 网络最大流的(Edmond Karp)算法
容量网络:在有向图D=(V,A),指定一个点为发点,记作 s,指定另一个点为收点,记作 t,其余点叫作中间点.对于A的每条弧(Vi,Ai),都对应一个权数 C ≥0,称为弧(Vi , Ai)的容量,将 ...
- nginx根据项目名实现内网地址转发
nginx根据访问的项目名进行内网地址转发 以下是nginx的配置信息: server { listen 8081; server_name localhost; #charset koi8-r; # ...
- hive学习2(Navicat连接hive)
Navicat连接hive 第一步:win下安装好mysql 第二步:win下安装Navicat 第三步:启动hadoop集群,启动hive 第四步:Navicat连接hive 在第四步中需先配置ss ...
- Android Sqlite 批量插入性能优化
db.beginTransaction(); try { for (...) { db.execSQL("...", new Object[]{}); } db.setTransa ...
- enter回车---焦点切换
$(function(){ $('.enter').bind('keydown',function(e){ var inputs = $('.enter_cash'); var key = e.whi ...
- js动态拼接参数到请求的url上
var queryConfig={ "page" : "index", "method" : 2, //1:按照方法A查看 2:按照方法B查 ...
- js抛物线
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SpringCloud教程 | 第五篇: 路由网关(zuul)
在微服务架构中,需要几个基础的服务治理组件,包括服务注册与发现.服务消费.负载均衡.断路器.智能路由.配置管理等,由这几个基础组件相互协作,共同组建了一个简单的微服务系统.一个简答的微服务系统如下图: ...
- Python文件练习
练习内容: 使用Python管理ini文件:实现查询,添加,删除,保存操作. 练习目的: 1.掌握文件基本操作 2.认识ini文件 3.了解ConfigParser: ini配置文件格式: 节:[se ...