Description
Input
Output
Sample Input
5 3 Inkfish Henry Carp Max Jericho Carp Max Carp 0
Sample Output
3
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
//建立一个结构体
struct node
{
int flag;//设置一个标记
struct node *next[26];
};
//建树
struct node *creat()
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node ));//申请内存
for(int i=0;i<26;i++)//循环遍历26个字母
{
p->next[i]=NULL;//设为空
}
p->flag=0;//表示没有被标记
return p;
}
//插入操作
void Insert(struct node *p,char *s)
{
int i,ans,len;
len=strlen(s);
for(i=0;i<len;i++)//循环遍历整个字符串
{
if(s[i]>='A' && s[i]<='Z')
ans=s[i]-'A';
else
ans=s[i]-'a';
if(p->next[ans]==NULL)
p->next[ans]=creat();//重新建树
p=p->next[ans];
}
p->flag=1;//设置为已经标记
}
//查找操作
int Find(struct node *p,char *s)
{
int i,ans,len;
len=strlen(s);//测出字符串长度
for(i=0;i<len;i++)//循环遍历整个字符串
{
if(s[i]>='A' && s[i]<='Z')
ans=s[i]-'A';
else
ans=s[i]-'a';
if(p->next[ans]==NULL)
return 0;
p=p->next[ans];
}
if(p->flag==1)
{
p->flag=0;
return 1;
}
return 0;
}
//释放内存
void Delete(struct node *p)
{
int i;
for(i=0;i<26;i++)
{
if(p->next[i]!=NULL)
Delete(p->next[i]);
}
free(p);//释放
}
int main()
{
int n,m,i,num;
char s[20000][100],s1[100];
struct node *tree;
while(scanf("%d %d",&n,&m),n)//输入操作
{
tree=creat();
for(i=0;i<n;i++)
{
scanf("%s",s[i]);
}
num=0;
while(m--)
{
scanf("%s",s1);
Insert(tree,s1);
}
for(i=0;i<n;i++)
{
num+=Find(tree,s[i]);
}
printf("%d\n",n-num);
Delete(tree);
}
return 0;
}