日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SCU - 4438 Censor

發布時間:2025/4/16 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SCU - 4438 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.

(1length of?w,p5?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


這題用KMP可以寫 但是KMP不會

但是用HASH暴力一下,HASH暴力出奇跡

1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <queue> 7 #include <set> 8 #include <map> 9 #include <string> 10 #include <math.h> 11 #include <stdlib.h> 12 #include <time.h> 13 using namespace std; 14 typedef unsigned long long ull; 15 const int maxn = 5e6 + 10; 16 const int seed = 13331; 17 ull HASH, s[maxn], p[maxn]; 18 char a[maxn], b[maxn], ans[maxn]; 19 void init() { 20 p[0] = 1; 21 for (int i = 1 ; i < maxn ; i++) 22 p[i] = p[i - 1] * seed; 23 } 24 int main() { 25 init(); 26 while(scanf("%s%s", a, b ) != EOF ) { 27 int lena = strlen(a), lenb = strlen(b); 28 if (lena > lenb) { 29 printf("%s\n", b); 30 continue; 31 } 32 HASH = 0; 33 for (int i = 0 ; i < lena ; i++) 34 HASH = HASH * seed + a[i]; 35 int top = 0; 36 s[0] = 0; 37 for (int i = 0 ; i < lenb ; i++) { 38 ans[top++] = b[i]; 39 s[top] = s[top - 1] * seed + b[i]; 40 if ( top >= lena && s[top] - s[top - lena]*p[lena] == HASH ) top -= lena; 41 } 42 for (int i = 0 ; i < top ; i++) 43 printf("%c", ans[i]); 44 printf("\n"); 45 } 46 return 0; 47 }

?



轉載于:https://www.cnblogs.com/qldabiaoge/p/9152695.html

總結

以上是生活随笔為你收集整理的SCU - 4438 Censor的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。