Message Flood

拼搏现实的明天。 2022-07-16 11:43 234阅读 0赞

Message Flood

Time Limit: 1500MS Memory Limit: 65536KB

Submit Statistic Discuss

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

  1. 5 3
  2. Inkfish
  3. Henry
  4. Carp
  5. Max
  6. Jericho
  7. Carp
  8. Max
  9. Carp
  10. 0

Example Output

  1. 3

Hint

Author

第9届中山大学程序设计竞赛预选赛

  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <algorithm>
  5. #include <stdio.h>
  6. #include<iomanip>
  7. using namespace std;
  8. int main()
  9. {
  10. int n, m;
  11. int i,j;
  12. while(~scanf("%d",&n) && n != 0)
  13. {
  14. scanf("%d",&m);
  15. map<string, int> mp;
  16. string name;
  17. for( i = 0; i < n; i++)
  18. {
  19. cin>>name;
  20. for( j=0; j<name.length(); j++)
  21. {
  22. name[j]=tolower(name[j]);
  23. }
  24. mp[name] = 1;
  25. }
  26. for( i = 0; i < m; i++)
  27. {
  28. cin>>name;
  29. for( j=0; j<name.length(); j++)
  30. {
  31. name[j]=tolower(name[j]);
  32. }
  33. if(mp[name] == 1)
  34. {
  35. n--;
  36. mp[name] = 0;
  37. }
  38. }
  39. printf("%d\n",n);
  40. }
  41. return 0;
  42. }

发表评论

表情:
评论列表 (有 0 条评论,234人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Flood Fill(漫水填充)算法

    Floodfill算法即漫水填充法,是区域填充法的一种,其实质是种子填充法,这种方法适用于对内定义区域的填充。 所谓内定义区域,是指区域内部所有像素具有同一颜色或亮度值,而区