MessageFlood
2015-06-18 17:00
246 查看
MessageFlood
TimeLimit: 1500ms Memory limit: 65536K
有疑问?点这里^_^
题目描述
Well,how do you feel about mobile phone? Your answer would probably besomething like that "It's so convenient
and benefits people alot". However, If you ask Merlin this question on the New Year'sEve, he will definitely answer "What a trouble! I have to keepmy fingers moving on the phone the whole night, because I have somany greeting message to send!" Yes, Merlin
has such a long namelist of his friends, and he would like to send a greeting message toeach of them. What's worse, Merlin has another long name list ofsenders that have sent message to him, and he doesn't want to sendanother message to bother them Merlin
is so polite that he alwaysreplies each message he receives immediately). So, before he beginsto send message, he needs to figure to how many friends are left tobe sent. Please write a program to help him. Here is something thatyou should note. First, Merlin's
friend list is not ordered, and eachname is alphabetic strings and case insensitive. These names areguaranteed to be not duplicated. Second, some senders may send morethan one message to Merlin, therefore the sender list may beduplicated. Third, Merlin is
known by so many people, that's why somemessage senders are even not included in his friend list.
输入
Thereare multiple test cases. In each case, at the first line there aretwo numbers n and m (1<=n,m<=20000),
which is the number offriends and the number of messages he has received. And then thereare n lines of alphabetic strings(the length of each will be lessthan 10), indicating the names of Merlin's friends, one per line.After that there are m lines of alphabetic
strings, which are thenames of message senders. The input is terminated by n=0.
输出
Foreach case, print one integer in one line which indicates the numberof left friends he must send.
示例输入
53
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0
示例输出
3
TimeLimit: 1500ms Memory limit: 65536K
有疑问?点这里^_^
题目描述
Well,how do you feel about mobile phone? Your answer would probably besomething like that "It's so convenient
and benefits people alot". However, If you ask Merlin this question on the New Year'sEve, he will definitely answer "What a trouble! I have to keepmy fingers moving on the phone the whole night, because I have somany greeting message to send!" Yes, Merlin
has such a long namelist of his friends, and he would like to send a greeting message toeach of them. What's worse, Merlin has another long name list ofsenders that have sent message to him, and he doesn't want to sendanother message to bother them Merlin
is so polite that he alwaysreplies each message he receives immediately). So, before he beginsto send message, he needs to figure to how many friends are left tobe sent. Please write a program to help him. Here is something thatyou should note. First, Merlin's
friend list is not ordered, and eachname is alphabetic strings and case insensitive. These names areguaranteed to be not duplicated. Second, some senders may send morethan one message to Merlin, therefore the sender list may beduplicated. Third, Merlin is
known by so many people, that's why somemessage senders are even not included in his friend list.
输入
Thereare multiple test cases. In each case, at the first line there aretwo numbers n and m (1<=n,m<=20000),
which is the number offriends and the number of messages he has received. And then thereare n lines of alphabetic strings(the length of each will be lessthan 10), indicating the names of Merlin's friends, one per line.After that there are m lines of alphabetic
strings, which are thenames of message senders. The input is terminated by n=0.
输出
Foreach case, print one integer in one line which indicates the numberof left friends he must send.
示例输入
53
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0
示例输出
3
/* 用的字典树,<span style="font-family:华文楷体, serif;">因为发送有重复的,所以以发送的建树,总的进行查询</span> */: #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <time.h> #include <cctype> #include <queue> #include <stack> #include <map> #include <set> #include <climits> #include <string> #include <iostream> #include <algorithm> #define RR freopen("input.txt","r",stdin) #define WW freopen("output.txt","w",stdout) #define INF 0x3f3f3f3f using namespace std; const int Max=20100; struct node { bool flag; node *next[26]; }; node * Creat() { node *p; p=new node; p->flag=false; for(int i=0;i<26;i++) { p->next[i]=NULL; } return p; } void Build(char *s,node *head) { node *p; p=head; int a; for(int i=0;s[i];i++) { if(s[i]>='A'&&s[i]<='Z') { a=s[i]+32-'a'; } else { a=s[i]-'a'; } if(p->next[a]==NULL) { p->next[a]=Creat(); } p=p->next[a]; } p->flag=true; } bool Rcher(char *s,node *head) { node *p; p=head; int a; for(int i=0;s[i];i++) { if(s[i]>='A'&&s[i]<='Z') { a=s[i]+32-'a'; } else { a=s[i]-'a'; } if(p->next[a]==NULL) { return false; } p=p->next[a]; } return p->flag; } int main() { int n,m; char s[Max][11]; char c[11]; while(scanf("%d",&n),n) { scanf("%d",&m); node *head; head=Creat(); for(int i=0;i<n;i++) { scanf("%s",s[i]); } for(int i=0;i<m;i++) { scanf("%s",c); Build(c,head); } int ans=0; for(int i=0;i<n;i++) { if(Rcher(s[i],head)) { ans++; } } cout<<n-ans<<endl; } return 0; }
相关文章推荐
- 图像处理(十九)基于移动最小二乘的图像变形-Siggraph 2006
- 面试题之spring
- MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏
- Oracle用RMAN还原种子数据库
- http://linux.linuxidc.com/
- 外部浏览器无法测试LAMP环境的解决方法
- 优化索引技巧
- ServiceStack.Text 的JSON序列号和反序列化
- C++杂记
- setConnectTimeout无效果
- Laravel-excel安装及使用
- 蓝桥杯:单位分数
- 【待续,啊啊啊啊】【找了一遍,最后成功!!】stm32 USART 防止发送缓冲区被新来的数据覆盖
- 可重入函数与不可重入函数
- A. Soldier and Bananas(CF546) Codeforces Round #304 (Div. 2)
- LinkedHashMap的用法
- js判断正整数
- Oracle同一节点副本数据库启动
- OJ嘻唰唰第一批之友元输出时间日期
- 学密码学一定得学程序