SCU4438 Censor(字符串哈希)

el/2023/12/3 2:40:36

http://acm.scu.edu.cn/soj/problem.action?id=4438

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 11 string 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

    abcaaabcbcbbbbabcab

Sample Output

    aab

非常好的一道题

s数组模拟栈,如果出现敏感词汇,top-= len ,从top开始覆盖

#include <bits/stdc++.h>
using namespace std;
using lon = unsigned long long;const int N = 5e6 + 5;
const lon base = 7;
lon h[N], h_w, h_p[N];
char s[N];
string p, w;
int top = 0;int main()
{h[0] = 1;for(int i = 1; i < N; i++) h[i] = h[i-1] * base;while(cin >> w >> p){h_w = 0; top = 0;for(int i = 0; i < w.length(); i++)h_w = h_w * base + w[i];for(int i = 0; i < p.length(); i++){s[top++] = p[i];h_p[top] = h_p[top-1] * base + p[i];if(top >= w.length() && h_p[top] - h_p[top-w.length()] * h[w.length()] == h_w)top -= w.length();}s[top] = '\0';cout << s << endl;}return 0;
}
/*
abc
aaabcbc
b
bbb
abc
ab*/

 


http://www.ngui.cc/el/3419460.html

相关文章

hdu 1166 敌兵布阵 ( 线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 151658 Accepted Submission(s): 62898 Problem Description C国的死对头A国这段时间正在进行军事演习&#xff0c;所以C国间谍头子Derek和他手下Ti…

NBUT 1723 有多少三元组 (思维)

https://ac.2333.moe/Problem/view.xhtml?id1723 有三个数组A&#xff0c;B&#xff0c;C&#xff0c;每个数组中有n个数&#xff0c;你可以从每个数组中找一个数&#xff0c;使得Ai<Bj<Ck ,(1<I,j,k<n)(1<n<100000,1<Ai,Bj,Ck<1000000)&#xff0c;…

NBUT 1746 可怕的班主任(思维)

https://vjudge.net/problem/2082745/origin 在学校里&#xff0c;一个班由n名学生组成。 在上午晨跑之前&#xff0c;同学们在班主任面前排成一条直线。 班主任对同学们的对齐方式不满意; 确实&#xff0c;同学们按照他们的学号顺序排列&#xff1a;1,2,3&#xff0c;......&…

NBUT 1749 论WC串的唯一性(思维)

https://ac.2333.moe/Problem/view.xhtml?id1749 wc 在爬塔时遇到了一串神秘字符&#xff0c;隐隐之中有一股力量从中透出 wc 很快发现了玄机&#xff0c;这个字符串中每一个含有“wc”的连续子序列都能为wc提供魔法值 找出字符串能为wc提供多少魔法值 注意如果某个连续子…

hud 5690 All X (快速幂 or 循环节)

https://vjudge.net/problem/387912/origin F(x,m)F(x,m) 代表一个全是由数字xx组成的mm位数字。请计算&#xff0c;以下式子是否成立&#xff1a; F(x,m) mod k ≡ cF(x,m) mod k ≡ c Input 第一行一个整数TT&#xff0c;表示TT组数据。 每组测试数据占一行&#xff0c;…

hdu 5694 BD String (递推)

http://acm.hdu.edu.cn/showproblem.php?pid5694 众所周知&#xff0c;度度熊喜欢的字符只有两个&#xff1a;B和D。 今天&#xff0c;它发明了一种用B和D组成字符串的规则&#xff1a; S(1)BS(1)B S(2)BBDS(2)BBD S(3)BBDBBDDS(3)BBDBBDD … S(n)S(n−1)Breverse(flip…

hdu 5695 Gym Class (拓扑排序)

https://vjudge.net/problem/387991/origin 众所周知&#xff0c;度度熊喜欢各类体育活动。 今天&#xff0c;它终于当上了梦寐以求的体育课老师。第一次课上&#xff0c;它发现一个有趣的事情。在上课之前&#xff0c;所有同学要排成一列&#xff0c; 假设最开始每个人有一个…

hud 5689 瞬间移动(组合数+逆元)

http://acm.hdu.edu.cn/showproblem.php?pid5698 有一个无限大的矩形&#xff0c;初始时你在左上角&#xff08;即第一行第一列&#xff09;&#xff0c;每次你都可以选择一个右下方格子&#xff0c;并瞬移过去&#xff08;如从下图中的红色格子能直接瞬移到蓝色格子&#xf…

多态中成员变量的使用

Dog 继承 Animal 类&#xff0c; 多态中成员变量没有重写。

Java之数据结构

前言 Java工具包提供了强大的数据结构。在Java中的数据结构主要包括以下几种接口和类&#xff1a; 枚举&#xff08;Enumeration&#xff09;位集合&#xff08;BitSet&#xff09;向量&#xff08;Vector&#xff09;栈&#xff08;Stack&#xff09;字典&#xff08;Dictio…