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 * 10^6), (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

KMP还是比较难呀,更何况是KMP变形,想了好久。。

// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define debug(a) cout<<#a<<" = "<<a<<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = +;
ll n, m, T, len, cnt, num, ans, Max, k;
char str[maxn], s[maxn];
int Next[maxn], pre[maxn]; void getNext() {
int j,k;
j=;
k=-;
Next[]=-;
while(j<cnt) {
if(k==-||s[j]==s[k]) Next[++j]=++k;
else k=Next[k];
}
} void KMP() {
getNext();
int i,j=, k = ;
char a[maxn];
for(i=; i<len; i++, k++) {
a[k] = str[i];
while(j>&&str[i]!=s[j]) j=Next[j];
if( s[j]==str[i] ) j++;
if(j==cnt) {
k -= cnt;
j=pre[k];
}
pre[k] = j;
a[k+] = '\0';
}
printf("%s\n", a);
} void input() {
while( ~scanf("%s%s", s, str) ) {
cnt = strlen(s);
len = strlen(str);
KMP();
}
} int main() {
input();
return ;
}

Censor SCU - 4438的更多相关文章

  1. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  2. SCU 4438 Censor(哈希+模拟栈)

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text \(p\). He ...

  3. SCU 4438:Censor

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...

  4. SCU 4438 Censor|KMP变形题

    传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...

  5. SCU 4438 Censor KMP/Hash

    题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...

  6. SCU 4438 Censor(Hash)题解

    题意:找出字符串p中的w串删除,反复操作,直到找不到w,输出这个串 思路:哈希处理前缀和,如果值相同就删掉. 代码: #include<iostream> #include<algo ...

  7. 四川省赛 SCU - 4438

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  8. SCU Censor

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...

  9. ACM:SCU 4437 Carries - 水题

    SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice  ...

随机推荐

  1. contos mysql 删除

    yum remove mysql mysql-server mysql-libs compat-mysql51rm -rf /var/lib/mysqlrm /etc/my.cnf查看是否还有mysq ...

  2. clone git 项目到 非空目录

    如果我们往一个非空的目录下 clone git 项目,就会提示错误信息: fatal: destination path '.' already exists and is not an empty ...

  3. ssm框架整合

    1.1 整合的思路 1.1.1 Dao层 使用mybatis框架.创建SqlMapConfig.xml.(可以是任意名字) 创建一个applicationContext-dao.xml   (通过sp ...

  4. docker容器多服务(不推荐)

    1.最常用方式配置进程管理工具Supervisor 2.最简单的就是把多个启动命令放到一个启动脚本里面,启动的时候直接启动这个脚本 第一种方式: 1.构建基础镜像 FROM lmurawsk/pyth ...

  5. BiLSTM学习

    转自:https://blog.csdn.net/aliceyangxi1987/article/details/77094970 https://blog.csdn.net/jojozhangju/ ...

  6. Laravel传值总结

    Laravel传值:with,view(),compact方法一:with public function index() { $title = '文章标题1'; return view('artic ...

  7. 遇到问题---hosts不起作用问题的解决方法

    c:\WINDOWS\system32\drivers\etc\hosts 文件的作用是添加 域名解析 定向 比如添加 127.0.0.1  www.baidu.com 那我们访问www.baidu. ...

  8. iOS 正则表达式(一)

    在iOS开发中,正则一直是最常用的,但也是一直记不住的,现在做一些简单的总结 我们在网上找的正则,要有'\',这个在iOS是转义符,需要'\\'这样 int main(int argc, const ...

  9. Appium环境搭建(一)

    python环境做测试,需要准备工具如下: 1.python2.7(这里使用的是python2你也可以选更高版本) 2.Appium(Window版) 3.Android SDK 4.Appium_P ...

  10. C# asp.net webapi下支持文件下载输出接口

    /// <summary>     /// 下载文件     /// </summary>     public class DownloadController : ApiC ...