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. wechat-注意事项

  2. vue中less的使用

    1.安装:npm install less less-loader --save 2.修改webpack.config.js文件,配置loader加载依赖,让其支持外部的less,在原来的代码上添加 ...

  3. socket发送http报文的疑惑(求高手指点一二)

    给8080或80端口的服务端(自己写的serverSocket服务端)发送字符串,此字符串按照http协议拼接而成,既是所谓的http报文.服务端接受成功.如果在报头与消息体之间少了“\r\n\r\n ...

  4. Elasticsearch5.x创建索引(Java)

    索引创建代码使用官方给的示例代码,我把它在java项目里实现了一遍. 官方示例 1.创建索引 /** * Java创建Index */ public void CreateIndex() { int ...

  5. gparted 不能起作用的时候,用fdisk

    我用的是vmware,从网上下载的centos 6.3版本,通过yum update,其最后更新为6系列的最终版本6.7. 没有仔细看磁盘空间,因为某种原因,为了远程登录,我安装了xfce4桌面,后来 ...

  6. GoWeb-Gin 文件上载

    前些日子,我们Node.JS了一把. 如今,我们还是回到我们伟大的GO来吧 今天,带领大家继续Golang的啦,而且是个上传文件的例子 先给大家看结果 1. 如果是windows端,你需要安装post ...

  7. cocos2d JS-(JavaScript) 动态生成方法的例子

    function User(properties) { for (var i in properties) { (function (which) { var p = i; which["g ...

  8. What is the reason for - java.security.spec.InvalidKeySpecException: Unknown KeySpec type: java.security.spec.ECPublicKeySpec

    支付中心Project重构完成,经过本地测试,并未发现问题.发布到测试环境后,测试发现请求光大扫码https接口时,出现了如下的异常: javax.net.ssl.SSLException: Serv ...

  9. sift拟合详解

    1999年由David Lowe首先发表于计算机视觉国际会议(International Conference on Computer Vision,ICCV),2004年再次经David Lowe整 ...

  10. QT 添加 lib库

    扒自网友文章: 一.添加第三方的头文件 首先,添加头文件  #include "ControlCAN.h" 然后,再将这个头文件放到工程的目录下 二.添加.lib文件 首先,将.l ...