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 ...
 
随机推荐
- HTML中--定义header和footer高度中间自适应
			
<html> <head> <meta charset="utf-8" /> <title></title> <s ...
 - Python 正在表达式
			
什么是正则表达式 正则表达式:是一组特殊的字符序列,又称为规则表达式,它能方便你检查一个字符串是否与某种模式匹配.通常用来检索和替换那些符合某些模式的文本.python中的re模块,实现了全部的正则表 ...
 - Python itsdangerous 生成token和验证token
			
代码如下 class AuthToken(object): # 用于处理token信息流程: # 1.更加给定的用户信息生成token # 2.保存生成的token,以便于后面验证 # 3.对用户请求 ...
 - 模块讲解----pickle模块(只在python用的序列化与反序列化)
			
特点 1.只能在python中使用,只支持python的基本数据类型. 2.可以处理复杂的序列化语法.(例如自定义的类的方法,游戏的存档等) 3.序列化的时候,只是序列化了整个序列对象,而不是内存地址 ...
 - U盘复制文件到最后5秒会卡住怎么办解决
			
现在的U盘容量已经非常大了,一般都有16G以上,为了能放单文件大于4G的数据大多数时候我们都是把U盘格式化为ntfs格式的,所以会出现不管是大文件还是小文件,当你往U盘里复制文件或者使用发送到U盘功能 ...
 - 27.给input边框和背景颜色设置全透明
			
给input边框和背景颜色设置全透明,但是里面的字不会消失 1.让背景颜色变透明(二选一) background-color:rgba(0,0,0,0); background:rgba(0,0,0, ...
 - TP图片上传
			
//控制器文件 public function index(){ if(!empty($_POST)){ $file = $_FILES["file"]; if(!isset($f ...
 - caffe中的caffemodel参数提取方法
			
需要的文件为:deploy.prototxt caffemodel net = caffe.Net(deploy.txt,caffe_model,caffe.TEST)具体代码: import caf ...
 - 详解Linux下iptables中的DNAT与SNAT设置(转)
			
详解Linux下iptables中的DNAT与SNAT设置 这篇文章主要介绍了Linux下iptables中的DNAT与SNAT设置,是Linux网络配置中的基础知识,需要的朋友可以参考下 原文连 ...
 - while练习题
			
# 1. 使用while循环输出1 2 3 4 5 6 8 9 10count = 1while count <= 10: if count == 7: count += 1 continue ...