题目描述
输入
输出
示例输入
5 3 Inkfish Henry Carp Max Jericho Carp Max Carp 0
示例输出
3
来源
#include <iostream>
#include<string>
#include<algorithm>
#include<memory.h>
using namespace std;
bool cmp(string a,string b)//字符串的比较;
{
return a<b;//升序比较;
}
string name[20001],t;//string定义字符串变量;
bool found [20001];
int n,m;
bool bi_search()//二分法查找;
{
int start=0,mid,end=n-1;
while(start<=end)
{
mid=(start+end)/2;
if(t==name[mid])
{
if(!found[mid])
{
found[mid]=true;//查找到;
return true;
}
else
return false;
}
else if(t<name[mid])//前端查找;
end=mid-1;
else//后端查找;
start=mid+1;
}
return false;
}
int main()
{
int i,count;//统计剩下的人名;
while(cin>>n&&n)
{
cin>>m;
memset(found,false,sizeof(found));
//memset(found,false,20001*sizeof(bool);//初始化;
for(i=0;i<n;i++)
{
cin>>name[i];
for(int j=0;j<name[i].length();j++)
if(name[i][j]>='A'&&name[i][j]<='Z')
name[i][j]+=32;
// name[i][j]=tolower(name[i][j]);//将大写字符变为小写字符;
}
count=n;
sort(name,name+n,cmp);//按照字典序升序排列;
for(i=0;i<m;i++)
{
cin>>t;
for(int j=0;j<t.length();j++)
t[j]=tolower(t[j]);//将大写字符变为小写字符;
if(bi_search())
count--;
}
cout<<count<<endl;
}
}