Message Flood
来源:互联网 发布:冒险小虎队知乎 编辑:程序博客网 时间:2024/05/22 06:55
Message Flood
Time Limit: 1500MS Memory Limit: 65536KB
Submit Statistic
Problem Description
Well, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits people a lot". However, If you ask Merlin this question on the New Year's Eve, he will definitely answer "What a trouble! I have to keep my fingers moving on the phone the whole night, because I have so many greeting message to send!" Yes, Merlin has such a long name list of his friends, and he would like to send a greeting message to each of them. What's worse, Merlin has another long name list of senders that have sent message to him, and he doesn't want to send another message to bother them Merlin is so polite that he always replies each message he receives immediately). So, before he begins to send message, he needs to figure to how many friends are left to be sent. Please write a program to help him. Here is something that you should note. First, Merlin's friend list is not ordered, and each name is alphabetic strings and case insensitive. These names are guaranteed to be not duplicated. Second, some senders may send more than one message to Merlin, therefore the sender list may be duplicated. Third, Merlin is known by so many people, that's why some message senders are even not included in his friend list.
Input
There are multiple test cases. In each case, at the first line there are two numbers n and m (1<=n,m<=20000), which is the number of friends and the number of messages he has received. And then there are n lines of alphabetic strings(the length of each will be less than 10), indicating the names of Merlin's friends, one per line. After that there are m lines of alphabetic strings, which are the names of message senders. The input is terminated by n=0.
Output
For each case, print one integer in one line which indicates the number of left friends he must send.
Example Input
5 3InkfishHenryCarpMaxJerichoCarpMaxCarp0
Example Output
3
Hint
#include<iostream>
#include<cstring>#include<algorithm>
using namespace std;
int cmp(string a,string b)
{
return a<b;
}
string t,a[20004];
int found[20005];
int n,m;
int bi_search()
{
int mid,start=0,end=n-1;
while(start<=end)
{
mid=(start+end)/2;
if(t==a[mid])
{
if(!found[mid])
{
found[mid]=1;
return 1;
}
else
return 0;
}
else if(t>a[mid])
start=mid+1;
else
end=mid-1;
}
return 0;
}
int main()
{
while(cin>>n&&n)
{
cin>>m;
memset(found,0,sizeof(found));
for(int i=0;i<n;i++)
{
cin>>a[i];
for(int j=0;j<a[i].length();j++)
if(a[i][j]>='A'&&a[i][j]<='Z')
a[i][j]=tolower(a[i][j]);
}
int count=n;
sort(a,a+n,cmp);
for(int i=0;i<m;i++)
{
cin>>t;
for(int j=0;j<t.length();j++)
if(t[j]>='A'&&t[j]<='Z')
t[j]=tolower(t[j]);
if(bi_search())
count--;
}
cout<<count<<endl;
}
}
0 0
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- Message Flood
- 解决npm run typings install无法下载typings文件问题
- 1002. A+B for Polynomials
- linux内核Kmalloc分配内存需要注意的问题(GFP_KERNEL可能会造成内核调度错误)
- 《大话数据结构》
- C#中重写(override)和覆盖(new)的区别
- Message Flood
- 触发器
- 实施微服务,我们需要哪些基础框架http://www.open-open.com/news/view/b7463e
- 关于socket通信UDP,TCP的理解
- zlib库 安装与使用
- 软件设计师考试(一)——总览
- 《大话数据结构》
- HDU2568
- kali linux的live u盘安装教程(带persistence)