hotal

来源:互联网 发布:网络上的灰色产业链 编辑:程序博客网 时间:2024/05/04 16:55

Problem Description

Last year summer Max straveled to California for his vacation. He had a great time there: took many photos, visited famous universities, enjoyed beatiful beaches and tasted various delicius foods. It is such a good trip that Max plans to travel there one more time this year. Max is satisfied with the accommodation of the hotel he booked last year but he lost the card of that hotel and can not remember quite clearly what its names is. So Max searched in web for the information of hotels in California and got piles of choice. Could you help Max pick out those that might be the right hotel?

Input

Input may consist of several test data sets. For each data set, it can be format as below:
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

For each test data set, just simply output one integer in a line telling the number of hotel in the list whose name matches the one Max remembered.

Sample Input

herbert2amazonherbert?ert*2amazonherbert*2amazonanythinghertber?2amazonherber

Sample Output

10
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];elsemp[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;}