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

5 3
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0

Sample Output

3

方法一:
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
#include <ctype.h> using namespace std; int main()
{
char str[30];
int len;
int n, m;
int i, j;
map<string,int>ma;
while(scanf("%d", &n)!=EOF)
{ if(n==0)
{
break;
}
scanf("%d%*c", &m );
ma.clear();
for(i=0; i<n; i++)
{
scanf("%s", str );
len = strlen(str );
for(j=0; j<len; j++)
{
str[j] = tolower( str[j] );
}
ma[str]++;
}
for(j=0; j<m; j++)
{
scanf("%s", str );
len = strlen(str);
for(i=0; i<len; i++)
{
str[i]=tolower(str[i]);
}
if(ma[str]>=1)
{n--;
ma[str]=0;
}
} printf("%d\n", n );
}
return 0;
}

方法二:

#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
#include <ctype.h>
using namespace std; int main()
{
char str[30];
int len;
int n, m;
int i, j;
// map<string,int>ma;
while(scanf("%d", &n)!=EOF)
{ if(n==0)
{
break;
}
scanf("%d%*c", &m );
map<string,int>ma;
for(i=0; i<n; i++)
{
scanf("%s", str );
len = strlen(str );
for(j=0; j<len; j++)
{
str[j] = tolower( str[j] );
}
ma[str]++;
}
for(j=0; j<m; j++)
{
scanf("%s", str );
len = strlen(str);
for(i=0; i<len; i++)
{
str[i]=tolower(str[i]);
}
ma.erase(str);
}
printf("%d\n", ma.size() );
}
return 0;
}

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. leetcode第一刷_Binary Tree Zigzag Level Order Traversal

    以出现的频率来看.树的层序遍历一定是考察的重点,除非工作人员想找题水数量. zigzag,还是有几道题的,层序的这个非常easy,假设是奇数层.reverse下面就可以.无他.我写的时候预计还不知道这 ...

  2. amchart 图表设置

    官网:https://www.amcharts.com/demos/ 属性介绍:https://docs.amcharts.com/3/javascriptcharts/AmLegend 安装 bow ...

  3. Android SDK环境搭建

    方法有二 方法一: Android SDK开发包国内下载地址 http://www.cnblogs.com/bjzhanghao/archive/2012/11/14/android-platform ...

  4. springmvc上传方法

    /** * * @param file 上传的文件 * @param filePath 上传到那个目录 * @return 上传后的文件名字 * @throws IOException */ publ ...

  5. subject相关信息

    记录一下我的错误信息 在ssm+shiro整合的时候,发现这样一个问题,第一次登录进去之后,然后再登录,输入错误的用户名和密码,竟然仍然登录成功,突然想起来了,是不是login之后,logout之后这 ...

  6. ubuntu 解决更换源失败问题

    用图形界面命令打开窗口在终端输入 gksudo nautilus打开一个图形窗口 (注意在这个图形窗口下 任何目录下的文件都是可以删除的) /ect/apt删除下面的sources.list和备份文件 ...

  7. [原]Nginx+Lua服务端合并静态文件

    http://homeway.me 0x01.About 源代码已经上传到github:https://github.com/grasses/nginx-lua-static-merger nginx ...

  8. Intellij idea subversion checkout error

    Subversion 1.8 and IntelliJ IDEA 13 Unlike its earlier versions, Subversion 1.8 support uses the nat ...

  9. 解决from lxml import etree 导入的时候,显示etree不存在

    问题: 当安装完lxml之后,发现使用 from lxml import etree  时,etree不可用 原因 :是lxml中没有etree包 解决: 去官网下载对应包:官网地址:http://l ...

  10. 初识Modbus TCP/IP-------------C#编写Modbus TCP客户端程序(一)

    转自:http://blog.csdn.net/thebestleo/article/details/52269999 首先我要说明一下,本人新手一枚,本文仅为同样热爱学习的同学提供参考,有不 对的地 ...