Message Flood

Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

 
 

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.

Sample Input

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

Sample Output

  1. 3
  2.  
  3. 方法一:
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <string>
  4. #include <map>
  5. #include <algorithm>
  6. #include <ctype.h>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. char str[30];
  13. int len;
  14. int n, m;
  15. int i, j;
  16. map<string,int>ma;
  17. while(scanf("%d", &n)!=EOF)
  18. {
  19.  
  20. if(n==0)
  21. {
  22. break;
  23. }
  24. scanf("%d%*c", &m );
  25. ma.clear();
  26. for(i=0; i<n; i++)
  27. {
  28. scanf("%s", str );
  29. len = strlen(str );
  30. for(j=0; j<len; j++)
  31. {
  32. str[j] = tolower( str[j] );
  33. }
  34. ma[str]++;
  35. }
  36. for(j=0; j<m; j++)
  37. {
  38. scanf("%s", str );
  39. len = strlen(str);
  40. for(i=0; i<len; i++)
  41. {
  42. str[i]=tolower(str[i]);
  43. }
  44. if(ma[str]>=1)
  45. {n--;
  46. ma[str]=0;
  47. }
  48. }
  49.  
  50. printf("%d\n", n );
  51. }
  52. return 0;
  53. }

方法二:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <string>
  4. #include <map>
  5. #include <algorithm>
  6. #include <ctype.h>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. char str[30];
  12. int len;
  13. int n, m;
  14. int i, j;
  15. // map<string,int>ma;
  16. while(scanf("%d", &n)!=EOF)
  17. {
  18.  
  19. if(n==0)
  20. {
  21. break;
  22. }
  23. scanf("%d%*c", &m );
  24. map<string,int>ma;
  25. for(i=0; i<n; i++)
  26. {
  27. scanf("%s", str );
  28. len = strlen(str );
  29. for(j=0; j<len; j++)
  30. {
  31. str[j] = tolower( str[j] );
  32. }
  33. ma[str]++;
  34. }
  35. for(j=0; j<m; j++)
  36. {
  37. scanf("%s", str );
  38. len = strlen(str);
  39. for(i=0; i<len; i++)
  40. {
  41. str[i]=tolower(str[i]);
  42. }
  43. ma.erase(str);
  44. }
  45. printf("%d\n", ma.size() );
  46. }
  47. return 0;
  48. }

STL 之map解决 Message Flood(原字典树问题)的更多相关文章

  1. STL MAP及字典树在关键字统计中的性能分析

    转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...

  2. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

  3. [POJ] #1002# 487-3279 : 桶排序/字典树(Trie树)/快速排序

    一. 题目 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 274040   Accepted: 48891 ...

  4. 字典树应用 - poj1002

    字典树应用 - poj 1002 Description Businesses like to have memorable telephone numbers. One way to make a ...

  5. POJ 2418 字典树

    题目链接:http://poj.org/problem?id=2418 题意:给定一堆树的名字,现在问你每一棵树[无重复]的出现的百分比,并按树名的字典序输出 思路:最简单的就是用map来写,关于字典 ...

  6. Go语言字典树定义及实现

    // trie 字典树实现 package Algorithm // 字典树节点 type TrieNode struct { children map[interface{}]*TrieNode i ...

  7. sdut Message Flood(c++ map)

    用字典树没过,学习了一下map; 参考博客:http://blog.csdn.net/zhengnanlee/article/details/8962432 AC代码 #include<iost ...

  8. Message Flood(map)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=203#problem/D 以前用字典树做过 #include <strin ...

  9. stl应用(map)或字典树(有点东西)

    M - Violet Snow Gym - 101350M Every year, an elephant qualifies to the Arab Collegiate Programming C ...

随机推荐

  1. .net core 2.0小白笔记(一):开发运行环境搭建

    小白一枚,有任何不妥之处敬请指教 这里不讨论什么设计模式,什么架构,什么什么,就是入门,简单的入门,虽然能跨平台,但是这里还是在win的环境下进行,不扯的那么远 其实官网文档写的挺不错的了,就是偶尔有 ...

  2. android dp 和 px 的相互转换

    在开发中,可能须要动态设置控件的大小 比如为一个gridview设置宽度: LinearLayout.LayoutParams linearParams2 = (LinearLayout.Layout ...

  3. 安装java运行环境

    1.查看java安装版本 执行命令java -version查看已安装java运行环境信息. 2.下载JDK 到sun官网下载需要的jdk版本,地址为:http://www.oracle.com/te ...

  4. python char()和ord()

    通过help 查看相关函数的帮助文档 >>>help (chr) chr(...) chr(i) -> character Return a string of one cha ...

  5. css 温故而知新 1px的问题

    解决方法1: //border @mixin border($pos, $color) { content: ""; position: absolute; transform-o ...

  6. STM32 寄存器库和固件库

    寄存器和固件库开发的差别和联系 固件库就是函数的集合,固件库函数的作用是向下负责与寄存器直接打交道.向上提供用户函数调用的接口(API). 在 51 的开发中我们经常的作法是直接操作寄存器,比方要控制 ...

  7. 解读Unity中的CG编写Shader系列3——表面剔除与剪裁模式

    在上一个样例中,我们得到了由mesh组件传递的信息经过数学转换至合适的颜色区间以颜色的形式着色到物体上. 这篇文章将要在此基础上研究片段的擦除(discarding fragments)和前面剪裁.后 ...

  8. oracle快速复制表数据

    方法一: 只复制表结构: create table table_name_new as select * from table_name_old where 1=2; 然后: alter sessio ...

  9. NIM游戏策略

    NIM取子游戏是由两个人面对若干堆硬币(或石子,或..)进行的游戏,游戏由两个人进行,设有k>=1堆硬币,各堆含有n1,n2,n3,n4.....,nk个硬币,游戏的目的就是选取最后剩下的硬币. ...

  10. 【Python+selenium Wendriver API】之鼠标悬停事件

    # encoding=utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import ...