Censor

frog is now a editor to censor so-called sensitive words (敏感词).

She has a long text p

. Her job is relatively simple -- just to find the first occurence of sensitive word w

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 1

string w. The second line contains 1 string p

.

(1≤length of w,p≤5⋅106

, w,p

consists of only lowercase letter)

Output

For each test, write 1

string which denotes the censored text.

Sample Input

    abc
aaabcbc
b
bbb
abc
ab

Sample Output

    a

    ab

题意: 给你两个字符串,要求每次可执行的操作是再下面的串里删去第一个串,直到不能删为止
思路分析 : 先对模式串进行一次 hash ,然后再对主串进行依次 hash ,然后依次检索每个位置,当二者的 hash 值相同时即代表是相同的字符串,在这里我们只是 hash 了一次,并且默认了不同的字符串hash值一定是不同的
代码示例:
using namespace std;
#define ll unsigned long long
const ll maxn = 5e6+5; char a[maxn], b[maxn];
ll len1, len2;
ll hash_num;
ll p = 19873;
ll pp[maxn]; void init(){
pp[0] = 1;
for(ll i = 1; i <= 5000000; i++){
pp[i] = pp[i-1]*p;
}
} void cal(){
hash_num = 0; for(ll i = 1; i <= len1; i++){
hash_num = hash_num*p+(a[i]-'a');
}
} ll sta[maxn];
ll ha[maxn]; bool check(ll pos){ if (pos >= len1 && ha[pos]-ha[pos-len1]*pp[len1] == hash_num){
return true;
}
return false;
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
init(); while(~scanf("%s%s", a+1, b+1)){
len1 = strlen(a+1);
len2 = strlen(b+1); cal();
//prllf("+++ %llu \n", hash); ll top = 1;
ha[0] = 0;
for(ll i = 1; i <= len2; i++){
sta[top] = b[i];
ha[top] = ha[top-1]*p+(b[i]-'a');
if (check(top)) top -= len1;
top++;
}
for(ll i = 1; i < top; i++){
printf("%c", sta[i]);
}
printf("\n");
}
return 0;
}


字符串 hash - 不停地删掉字母的更多相关文章

  1. 【题解】 bzoj3555: [Ctsc2014]企鹅QQ (字符串Hash)

    题面戳我 Solution 我们分析题意,他要求的是两个字符串只有一个字符不同,然后我们再看长度\(L \leq 200\),显然我们就可以把每一位删除后\(Hash\),然后判断相同个数即可 我一开 ...

  2. CodeForces 1056E - Check Transcription - [字符串hash]

    题目链接:https://codeforces.com/problemset/problem/1056/E One of Arkady's friends works at a huge radio ...

  3. 转载:字符串hash总结(hash是一门优雅的暴力!)

    转载自:远航休息栈 字符串Hash总结 Hash是什么意思呢?某度翻译告诉我们: hash 英[hæʃ] 美[hæʃ]n. 剁碎的食物; #号; 蔬菜肉丁;vt. 把…弄乱; 切碎; 反复推敲; 搞糟 ...

  4. cdoj1092-韩爷的梦 (字符串hash)【hash】

    http://acm.uestc.edu.cn/#/problem/show/1092 韩爷的梦 Time Limit: 200/100MS (Java/Others)     Memory Limi ...

  5. 转载:字符串HASH

    转载自:Slager_Z 字符串Hash总结 Hash是什么意思呢?某度翻译告诉我们: hash 英[hæʃ] 美[hæʃ]n. 剁碎的食物; #号; 蔬菜肉丁;vt. 把…弄乱; 切碎; 反复推敲; ...

  6. (通俗易懂小白入门)字符串Hash+map判重——暴力且优雅

    字符串Hash 今天我们要讲解的是用于处理字符串匹配查重的一个算法,当我们处理一些问题如给出10000个字符串输出其中不同的个数,或者给一个长度100000的字符串,找出其中相同的字符串有多少个(这样 ...

  7. 字符串Hash学习笔记

    [toc] # 以下内容作废,太多错误了,等我有时间重写 说一下什么是Hash,说白了就是把一大坨字符用一些神奇的数来表示,可以说是把字符加密了. 简单一点就是一个像函数一样的东西,你放进去一个值,它 ...

  8. [知识点]字符串Hash

    1.前言 字符串的几大主要算法都多少提及过,现在来讲讲一个称不上什么算法, 但是非常常用的东西——字符串Hash. 2.Hash的概念 Hash更详细的概念不多说了,它的作用在于能够对复杂的状态进行简 ...

  9. 【BZOJ-3555】企鹅QQ 字符串Hash

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1545  Solved: 593[Submit][Statu ...

随机推荐

  1. centOS 重启 php-fpm

     ps axo pid,%cpu,%mem,comm |grep php-fpm ps aux | grep php-fpm pkill -9 php-fpm /etc/init.d/php-fpm ...

  2. poj 3279(开关问题)(待完成)

    传送门:Problem 3279 #include<iostream> #include<cstdio> #include<cstring> using names ...

  3. vue-cil 打包爬坑(解决)

    1.打包成功不报错,但是打开页面啥都没有?  解决:文件位置:config目录下index.js文件更改assetsPublicPath属性:文件里面有两个assetsPublicPath属性,也就是 ...

  4. 1471 - Defense Lines

    After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...

  5. H3C IEEE EUI-64格式

  6. next-i18next 常见Bug记录

    TypeError: Cannot read property 'wait' of null 此处根本原因为next版本(使用withNamespaces导入命名空间报错) ^5.0.0版本不支持导入 ...

  7. Python7_内置函数总结

    Python Built-In 函数: str(obj) :输入(对象),返回一个对象的string格式: isinstance(object,classinfo):判断一个对象是否是一个已知的类型, ...

  8. c++ list的坑

    std::list为空时调用pop_front的访问越界问题 std::list为空时调用pop_back访问越界问题 所以在使用pop_front . pop_back要先判断list是否为空 st ...

  9. ASP.NET MVC API以及.Core API进行安全拦截和API请求频率控制

    安全拦截思路: 根据IP以及请求次数,该IP超过规定请求次数,就有很大可能是非正常用户进行的请求(比如WEB攻击),这时候进行拦截,拦截成功会提示:The allowed number of requ ...

  10. 【题解】P3645 [APIO2015]雅加达的摩天楼(分层图最短路)

    [题解]P3645 [APIO2015]雅加达的摩天楼(分层图最短路) 感觉分层图是个很灵活的东西 直接连边的话,边数是\(O(n^2)\)的过不去 然而我们有一个优化的办法,可以建一个新图\(G=( ...