Problem Description
Input
For the first line, there is one string consist of ‘*’, ‘?’ and ‘a’-‘z’ characters. This string represents the hotel name that Max can remember. The ‘*’ and ‘?’ is wildcard characters. ‘*’ matches zero or more lowercase character(s), and ‘?’ matches only one lowercase character.
In the next line there is one integer n (1<=n<=10000) representing the number of hotel Max found, and then n lines follow. Each line contains one string of lowercase character(s), the name of the hotel.
The length of every string doesn’t exceed 50.
Output
Sample Input
herbert 2 amazon herbert ?ert* 2 amazon herbert * 2 amazon anything hertber? 2 amazon herber
Sample Output
1 0
2
0
#include<iostream>
#include<string.h>
using namespace std;
int n,cnt;
char s1[100],s2[100];
bool mp[100][100];
bool DP(char *s1,char *s2)
{
int len1,len2,i,j;
len1=strlen(s1);
len2=strlen(s2);
memset(mp,false,sizeof(mp));
mp[0][0]=true;
for(i=1;i<=len1;i++)
{
for(j=0;j<=len2;j++)
{
if(s1[i-1]=='*')
{
if(j==0)
mp[i][j]=mp[i-1][j];
else
mp[i][j]=mp[i-1][j]|mp[i][j-1];
}
else if(j)
{
if(s1[i-1]=='?')
mp[i][j]=mp[i-1][j-1];
else if(s1[i-1]==s2[j-1])
mp[i][j]=mp[i-1][j-1];
}
}
}
return mp[len1][len2];
}
int main()
{
freopen("a.in","r",stdin);
while(cin>>s1)
{
cin>>n;
cnt=0;
while(n--)
{
cin>>s2;
if(DP(s1,s2))
cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
713




被折叠的 条评论
为什么被折叠?



