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 ...
随机推荐
- EOS 帐户权限操作--你找不到的干货 (原创) 续集-EOS 3.0
https://eosfans.io/topics/372 关于2.0权限问题请移步https://eosfans.io/topics/28 目录 查看权限 改变权限 增加权限 删除权限 查看权限 有 ...
- Python小数据池,代码块
今日内容一些小的干货 一. id is == 二. 代码块 三. 小数据池 四. 总结 python小数据池,代码块的最详细.深入剖析 一. id is == 二. 代码块 三. 小数据池 四. ...
- [Java in NetBeans] Lesson 02. Variables, Data Types and Assignment.
这个课程的参考视频在youtube. 主要学到的知识点有: Data Type: int, char, String, double, boolean. When into printf, int ( ...
- Ubuntu下安装eclipse遇到的问题
今天在Ubuntu中安装eclipse时遇到如下问题: 解决方法: 打开eclipse安装目录下eclipse.ini文件 在文件最开头(注:一定是最开头)加上如下语句(-startup前面两行),第 ...
- cocos2dx 3.x 网络循环接收数据(RakNet::Packet* packet)单步网络接收
void FriendFightLayer::update(float dt) { dealWithPacket(dt); if (m_isNeedSwitchToLobby) { PublicMet ...
- react native初识
开发的第一步就是搭建rn的开发环境,你可以去官网去查看教程也可以 点击 http://bbs.reactnative.cn/topic/10 进去查看window的开发环境安装的教程:注意:很关键的一 ...
- node.js初识07
之前有说过,nodejs是 没有web容器的,阿帕奇是自带的web容器,如果希望node达到阿帕奇的效果,即http://127.0.0.1:3000/a/b/c.html 出现这样的链接访问页面,所 ...
- Lua class
local _class = {} function class(super) local class_type = {} class_type.ctor = false class_type.sup ...
- Oracle的下载安装教程以及所出现的问题
1.下载地址 64位 https://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win64soft ...
- EL的隐含对象(一)【页面上下文对象】
页面上下文对象为pageContext,用于访问JSP内置对象(例如:request.response.out.session.exception.page等)和ServletContext.在获取到 ...