四川第七届 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 ...
随机推荐
- C++中随机数的生成
1.随机数由生成器和分布器结合产生 生成器generator:能够产生离散的等可能分布数值 分布器distributions: 能够把generator产生的均匀分布值映射到其他常见分布,如均匀分布u ...
- Logistic回归python实现
2017-08-12 Logistic 回归,作为分类器: 分别用了梯度上升,牛顿法来最优化损失函数: # -*- coding: utf-8 -*- ''' function: 实现Logistic ...
- JDK各个版本的新特性jdk1.5-jdk8[转]
JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一 ...
- ADO.Net连接Mysql
首先下载一个mysql.data.dll拷贝到bin下面并引用一下 using MySql.Data.MySqlClient; class Program { static void Main(str ...
- windows系统JDK的安装及环境配置
本文转载至:http://blog.csdn.net/sweetburden2011/article/details/8881181 一:JDK的安装 1. 首先上甲骨文公司的官方网站下载JDK的 ...
- 【转载】JAVA中线程的两种实现方法-实现Runnable接口和继承Thread类
转自: http://blog.csdn.net/sunguangran/article/details/6069317 非常感谢原作者,整理的这么详细. 在java中可有两种方式实现多线程,一种是继 ...
- Codeforces 895C Square Subsets:状压dp【组合数结论】
题目链接:http://codeforces.com/problemset/problem/895/C 题意: 给你n个数a[i].(n <= 10^5, 1 <= a[i] <= ...
- 关于html的一些杂技
html预定义字符指的是 :< > html实体指的是 $amp 等 php中htmlspeciachar()就是讲html预定义字符转换成html实体. 浏览器渲染时,会将html实 ...
- dp2--合并石子(一)
dp2--合并石子(一) 一.心得 二.题目 石子合并(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 有N堆石子排成一排,每堆石子有一定的数量.现要将 ...
- C# WPF DataGrid 隔行变色及内容居中对齐
C# WPF DataGrid 隔行变色及内容居中对齐. dqzww NET学习0 先看效果: 前台XAML代码: <!--引入样式文件--> <Window.Resourc ...