Description
Last year summer Max traveled to California for his vacation. He had a great time there: took many photos, visited famous universities, enjoyed beautiful beaches and tasted various delicious foods. It is such a good trip that Max plans to travel there one more time this year. Max is satisfied with the accommodiation of the hotel he booked last year but he lost the card of that hotel and can not remember quite clearly what its name is. So Max searched in the 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 consisting 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 charcter. 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 remenbered.
#include "stdio.h"
#include <memory.h>
char str[1000];
char s[1000];
bool Match(int strloc,int sloc)
{
if(str[strloc] == '\0' && s[sloc] == '\0')
return true;
if(true)
{
if(str[strloc] == '*')
{
if(str[strloc + 1] == '\0')
return true;
if(str[strloc + 1] == '?')
{
if(s[sloc] == '\0')
return false;
else
{
str[strloc +1] = '*';
return Match(strloc + 1,sloc + 1);
}
}
if(str[strloc + 1] == '*')
return Match(strloc + 1,sloc);
for(int i = sloc;s[i] != '\0';i ++)
if(s[i] == str[strloc + 1])
{
if(Match(strloc + 1,i))
return true;
}
}
else if((str[strloc] == '?'&& s[sloc] != '\0') || str[strloc] == s[sloc])
{
return Match(strloc + 1,sloc + 1 );
}
}
return false;
}
int main()
{
memset(str,'\0',sizeof(str));
memset(s,'\0',sizeof(s));
int num;
int sum;
while(true)
{
num = 0;
if(scanf("%s",str) == EOF)break;
scanf("%d",&sum);
for(int i = 0;i < sum;i ++)
{
scanf("%s",s);
if(Match(0,0))
num ++;
}
printf("%d\n",num);
}
return 1;
}