Censor SCU - 4438
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的更多相关文章
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- SCU 4438 Censor(哈希+模拟栈)
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text \(p\). He ...
- SCU 4438:Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...
- SCU 4438 Censor|KMP变形题
传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...
- SCU 4438 Censor KMP/Hash
题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...
- SCU 4438 Censor(Hash)题解
题意:找出字符串p中的w串删除,反复操作,直到找不到w,输出这个串 思路:哈希处理前缀和,如果值相同就删掉. 代码: #include<iostream> #include<algo ...
- 四川省赛 SCU - 4438
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- SCU Censor
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text p . Her j ...
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
随机推荐
- Observer(__ob__: Observer) 对象添加属性
重点通过这句话给对象添加属性: this.$set(r,'upshow',false); 在data中定义laws来装从接口中请求到数据 data(){ return{ laws:[],//法律依据 ...
- 常见的local variable 'x' referenced before assignment问题
def fun1(): x = 5 def fun2(): x *= 2 return x return fun2() 如上代码,调用fun1() 运行会出错:UnboundLocalError: l ...
- php循环方法实现先序、中序、后序遍历二叉树
二叉树是每个节点最多有两个子树的树结构.通常子树被称作“左子树”(left subtree)和“右子树”(right subtree). <?php class Node { public $v ...
- Java 基础 变量和运算符
Java基础语法 第1章 变量 1.1 变量概述 1.2 计算机存储单元 1.3 基本类型之4类8种 1.4 常量与类型 1.5 定义变量(创建变量) 1.6 变量使用的注意事项 1.7 数据类型 ...
- 2018-2019-1 20189221 《Linux内核原理与分析》第八周作业
2018-2019-1 20189221 <Linux内核原理与分析>第八周作业 实验七 编译链接过程 gcc –e –o hello.cpp hello.c / gcc -x cpp-o ...
- python demjson
这个是第三方的json库 首先安装 http://deron.meranda.us/python/demjson/ demjson-2.2.4.tar.gz #tar -xzf demjson-2.2 ...
- android 注入so
https://www.52pojie.cn/thread-564459-1-1.html
- 巧用CurrentThread.Name来统一标识日志记录(完结篇)
▄︻┻┳═一Agenda: ▄︻┻┳═一巧用CurrentThread.Name来统一标识日志记录 ▄︻┻┳═一巧用CurrentThread.Name来统一标识日志记录(续) ▄︻┻┳═一巧用Cur ...
- Mysql date,datetime的区别以及相互转换
参考:https://blog.csdn.net/a3025056/article/details/62885104/ 在数据库中一直有这三个时间类型有点搞不太清楚. 今天就来说一下之间的区别,其实是 ...
- node.js初识06
node中的fs文件系统 var http = require("http"); var fs = require("fs"); var server = ht ...