18101 网络语言过滤器
时间限制:1000MS 内存限制:65535K
题型: 编程题 语言: G++;GCC;VC
Description
管理网上发布的言论,对管理员来说总是一麻烦事,其中一个常见的问题是网络上的言论往往混杂一些不文明用语,例如 SB、草*马等。管理员希望有一个程序能够自动将言论中的不文明用语变为一连串的*号。但另一个需要解决的问题是,网上 用户常常在不文明用语中间加入空格、逗号、下划线,以躲过程序的判别,例如S B、S_B、S, ,B这些都应该被视为不文明用语。但 下面情况除外:He is boy,语子中,因为s是is中的一个字母,b是boy中的一个字母,不应该再分离但组成s b。 注:大小写不区分
输入格式
一行由半角字母、标点和空格构成的网文,以'\n'结束,最多不超过10000个字符 第二行是一个数字T,表示不文明词语的个数,最多不超过100个 此后T行,每行一个词语,由字母构成,每个词语不超过10个字母
输出格式
以*号替换了不文明词语的网文
输入样例
You are S _B. She is shit. He is boy. They are sB. 2 SB shit
输出样例
You are ****. She is ****. He is boy. They are **.
作者
admin
思路:
暴力对比字符串 个人认为自己模拟码力还欧克
1.提取出每个单词
2.顺序组合单词与屏蔽词对比(尽量长度最长开始组合)
3.执行屏蔽
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
char input[10005];
char shit[105][15];
int index_word[5005];
int n;
void readshit()
{
getchar();
for(int i=0;i<n;++i){
gets(shit[i]);
strlwr(shit[i]);
//puts(shit[i]);
}
}
void divide()
{
index_word[0]=0;
int len_input=strlen(input);
for(int i=0,gut_word=0;i<len_input;++i){
if(input[i]==' '||input[i]==','||input[i]=='_'||input[i]=='.'){
if(gut_word){
gut_word=0;
++index_word[0];//the count of word
index_word[index_word[0]*2]=i-1;//the index of the end of the word
}
}
else{
if(!gut_word){//the first c of the word
gut_word=1;
index_word[index_word[0]*2+1]=i;
}
}
}
}
void checked(int s,int e)
{
for(int i=s;i<=e;++i)
input[i]='*';
}
void check_more()
{
char single[15];
for(int w=10;w>0;--w){
for(int i=1;i<=index_word[0];++i){
int len=0;
int add=0;
int j=0;
while(i<index_word[0]&&len+index_word[(i+add)*2]-index_word[(i+add)*2-1]+1<=w){
int e=index_word[(i+add)*2],s=index_word[(i+add)*2-1];
int c=0;
for(j=len;j<len+e-s+1;++j,++c){
single[j]=input[s+c];
}
len+=e-s+1;
++add;
}
//miss the last word
single[j]='\0';
strlwr(single);
//puts(single);
for(int k=0;k<n;++k){
if(!strcmp(single,shit[k])){
checked(index_word[i*2-1],index_word[(i+add-1)*2]);
//puts(single);
break;
}
}
}
}
//fix the last word
int e=index_word[index_word[0]*2],s=index_word[index_word[0]*2-1],i;
for(i=0;i<e-s+1;++i){
single[i]=input[s+i];
}
single[i]='\0';
strlwr(single);
for(int k=0;k<n;++k){
if(!strcmp(single,shit[k])){
checked(s,e);
//puts(single);
break;
}
}
}
void check_single()
{
char single[15];
for(int i=1;i<=index_word[0];++i){
int s=index_word[i*2-1],e=index_word[i*2],j;
for(j=0;j<e-s+1;++j){
single[j]=input[s+j];
}
single[j]='\0';
strlwr(single);
for(int k=0;k<n;++k){
if(!strcmp(single,shit[k])){
checked(s,e);
break;
}
}
}
}
//#define local
int main()
{
#ifdef local
freopen("input.txt","r",stdin);
#endif
gets(input);
cin>>n;
readshit();
divide();
//cout<<index_word[0];
check_more();
puts(input);
return 0;
}