蒟蒻要被虐哭啦!
没有描述
我简单说一下
给串T里面有”?”,可以与任意一种字符匹配
给串S
如果T为S子串则输出”God bless You!”
否则输出”Game Over!”
共有n组数据
一个带有通配符的字符串匹配问题
在KMP上做小小的修改即可AC
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char s1[100101],s2[100101];
int cnt;
int net[100101];
void find()
{
int len=strlen(s2);
int t1=0,t2=-1;
net[0]=-1;
while(t1<len)
{
if(t2==-1||s2[t1]==s2[t2]||s2[t2]=='?')//修改在此
{
net[++t1]=++t2;
}
else t2=net[t2];
}
return;
}
int kmp()
{
int flag=0;
int len1=strlen(s1);
int len2=strlen(s2);
int t1=0;
int t2=0;
while(t1<len1)
{
if(t2==-1||s1[t1]==s2[t2]||s2[t2]=='?')//修改在此
t1++,t2++;
else
t2=net[t2];
if(t2==len2)
{
flag=1;
break;
}
}
if(!flag) printf("Game Over!\n");
else printf("God bless You!\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",s2);
scanf("%s",s1);
find();
kmp();
}
return 0;
}